File tree 2 files changed +17
-1
lines changed
2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -222,7 +222,11 @@ function respond(ctx) {
222
222
223
223
// status body
224
224
if ( null == body ) {
225
- body = ctx . message || String ( code ) ;
225
+ if ( ctx . req . httpVersionMajor >= 2 ) {
226
+ body = String ( code ) ;
227
+ } else {
228
+ body = ctx . message || String ( code ) ;
229
+ }
226
230
if ( ! res . headersSent ) {
227
231
ctx . type = 'text' ;
228
232
ctx . length = Buffer . byteLength ( body ) ;
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ describe('app.response', () => {
9
9
const app1 = new Koa ( ) ;
10
10
app1 . response . msg = 'hello' ;
11
11
const app2 = new Koa ( ) ;
12
+ const app3 = new Koa ( ) ;
12
13
13
14
it ( 'should merge properties' , ( ) => {
14
15
app1 . use ( ( ctx , next ) => {
@@ -31,4 +32,15 @@ describe('app.response', () => {
31
32
. get ( '/' )
32
33
. expect ( 204 ) ;
33
34
} ) ;
35
+
36
+ it ( 'should not include status message in body for http2' , async ( ) => {
37
+ app3 . use ( ( ctx , next ) => {
38
+ ctx . req . httpVersionMajor = 2 ;
39
+ ctx . status = 404 ;
40
+ } ) ;
41
+ const response = await request ( app3 . listen ( ) )
42
+ . get ( '/' )
43
+ . expect ( 404 ) ;
44
+ assert . equal ( response . text , '404' ) ;
45
+ } ) ;
34
46
} ) ;
You can’t perform that action at this time.
0 commit comments