Skip to content

Commit 9905199

Browse files
edevildead-horse
authored andcommitted
fix: Status message is not supported on HTTP/2 (#1264)
1 parent 71aaa29 commit 9905199

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/application.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,11 @@ function respond(ctx) {
222222

223223
// status body
224224
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+
}
226230
if (!res.headersSent) {
227231
ctx.type = 'text';
228232
ctx.length = Buffer.byteLength(body);

test/application/response.js

+12
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ describe('app.response', () => {
99
const app1 = new Koa();
1010
app1.response.msg = 'hello';
1111
const app2 = new Koa();
12+
const app3 = new Koa();
1213

1314
it('should merge properties', () => {
1415
app1.use((ctx, next) => {
@@ -31,4 +32,15 @@ describe('app.response', () => {
3132
.get('/')
3233
.expect(204);
3334
});
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+
});
3446
});

0 commit comments

Comments
 (0)