File tree Expand file tree Collapse file tree 2 files changed +7
-12
lines changed Expand file tree Collapse file tree 2 files changed +7
-12
lines changed Original file line number Diff line number Diff line change @@ -14,16 +14,18 @@ export const html = () =>
14
14
. derive ( ( { set } ) => ( {
15
15
sanitize,
16
16
html ( value : string ) {
17
- set . headers [ 'content-type' ] = 'text/html; charset=utf8'
18
-
19
- return new Response ( value , set )
17
+ return new Response ( value , {
18
+ headers : {
19
+ 'content-type' : 'text/html; charset=utf8'
20
+ }
21
+ } )
20
22
}
21
23
} ) )
22
24
. onAfterHandle ( ( { set } , response ) => {
23
25
if ( typeof response === 'string' && isHTML ( response ) ) {
24
26
set . headers [ 'content-type' ] = 'text/html; charset=utf8'
25
27
26
- return response
28
+ return new Response ( response , set )
27
29
}
28
30
} )
29
31
Original file line number Diff line number Diff line change @@ -32,18 +32,11 @@ describe('HTML', () => {
32
32
expect ( res . headers . get ( 'Content-Type' ) ) . toContain ( 'text/html' )
33
33
} )
34
34
35
- it ( 'auto return html in-sensitive' , async ( ) => {
36
- const app = new Elysia ( ) . use ( html ( ) ) . get ( '/' , ( ) => `<!doCTypE HTML>` )
37
-
38
- const res = await app . handle ( req ( '/' ) )
39
- expect ( res . headers . get ( 'Content-Type' ) ) . toContain ( 'text/html' )
40
- } )
41
-
42
35
it ( 'inherits header' , async ( ) => {
43
36
const app = new Elysia ( ) . use ( html ( ) ) . get ( '/' , ( { html, set } ) => {
44
37
set . headers . Server = 'Elysia'
45
38
46
- return html
39
+ return html ( "<h1>Hi</h1>" )
47
40
} )
48
41
49
42
const res = await app . handle ( req ( '/' ) )
You can’t perform that action at this time.
0 commit comments