@@ -92,7 +92,7 @@ export const empty = (
9292 */
9393export const redirect = (
9494 location : string | URL ,
95- options ?: Options . WithContentType | undefined
95+ options ?: Options . WithContent | undefined
9696) : HttpServerResponse => {
9797 const headers = Headers . fromRecordUnsafe ( { location : location . toString ( ) } )
9898 return makeResponse ( {
@@ -213,16 +213,18 @@ export const htmlStream = <
213213 */
214214export const json = (
215215 body : unknown ,
216- options ?: Options . WithContent | undefined
217- ) : Effect . Effect < HttpServerResponse , Body . HttpBodyError > =>
218- Effect . map ( Body . json ( body ) , ( body ) =>
216+ options ?: Options . WithContentType | undefined
217+ ) : Effect . Effect < HttpServerResponse , Body . HttpBodyError > => {
218+ const headers = options ?. headers ? Headers . fromInput ( options . headers ) : Headers . empty
219+ return Effect . map ( Body . json ( body , getContentType ( options , headers ) ) , ( body ) =>
219220 makeResponse ( {
220221 status : options ?. status ?? 200 ,
221222 statusText : options ?. statusText ,
222- headers : options ?. headers && Headers . fromInput ( options . headers ) ,
223+ headers,
223224 cookies : options ?. cookies ,
224225 body
225226 } ) )
227+ }
226228
227229/**
228230 * @since 4.0.0
@@ -235,16 +237,18 @@ export const schemaJson = <A, I, RD, RE>(
235237 const encode = Body . jsonSchema ( schema , options )
236238 return (
237239 body : A ,
238- options ?: Options . WithContent | undefined
239- ) : Effect . Effect < HttpServerResponse , Body . HttpBodyError , RE > =>
240- Effect . map ( encode ( body ) , ( body ) =>
240+ options ?: Options . WithContentType | undefined
241+ ) : Effect . Effect < HttpServerResponse , Body . HttpBodyError , RE > => {
242+ const headers = options ?. headers ? Headers . fromInput ( options . headers ) : Headers . empty
243+ return Effect . map ( encode ( body , getContentType ( options , headers ) ) , ( body ) =>
241244 makeResponse ( {
242245 status : options ?. status ?? 200 ,
243246 statusText : options ?. statusText ,
244- headers : options ?. headers && Headers . fromInput ( options . headers ) ,
247+ headers,
245248 cookies : options ?. cookies ,
246249 body
247250 } ) )
251+ }
248252}
249253
250254/**
@@ -253,34 +257,38 @@ export const schemaJson = <A, I, RD, RE>(
253257 */
254258export const jsonUnsafe = (
255259 body : unknown ,
256- options ?: Options . WithContent | undefined
257- ) : HttpServerResponse =>
258- makeResponse ( {
260+ options ?: Options . WithContentType | undefined
261+ ) : HttpServerResponse => {
262+ const headers = options ?. headers ? Headers . fromInput ( options . headers ) : Headers . empty
263+ return makeResponse ( {
259264 status : options ?. status ?? 200 ,
260265 statusText : options ?. statusText ,
261- headers : options ?. headers && Headers . fromInput ( options . headers ) ,
266+ headers,
262267 cookies : options ?. cookies ,
263- body : Body . jsonUnsafe ( body )
268+ body : Body . jsonUnsafe ( body , getContentType ( options , headers ) )
264269 } )
270+ }
265271
266272/**
267273 * @since 4.0.0
268274 * @category constructors
269275 */
270276export const urlParams = (
271277 body : UrlParams . Input ,
272- options ?: Options . WithContent | undefined
273- ) : HttpServerResponse =>
274- makeResponse ( {
278+ options ?: Options . WithContentType | undefined
279+ ) : HttpServerResponse => {
280+ const headers = options ?. headers ? Headers . fromInput ( options . headers ) : Headers . empty
281+ return makeResponse ( {
275282 status : options ?. status ?? 200 ,
276283 statusText : options ?. statusText ,
277- headers : options ?. headers && Headers . fromInput ( options . headers ) ,
284+ headers,
278285 cookies : options ?. cookies ,
279286 body : Body . text (
280287 UrlParams . toString ( UrlParams . fromInput ( body ) ) ,
281- "application/x-www-form-urlencoded"
288+ getContentType ( options , headers ) ?? "application/x-www-form-urlencoded"
282289 )
283290 } )
291+ }
284292
285293/**
286294 * @since 4.0.0
0 commit comments