Skip to content

Commit

Permalink
fix: Status message is not supported on HTTP/2 (#1264)
Browse files Browse the repository at this point in the history
  • Loading branch information
edevil authored and dead-horse committed Nov 9, 2018
1 parent 71aaa29 commit 9905199
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,11 @@ function respond(ctx) {

// status body
if (null == body) {
body = ctx.message || String(code);
if (ctx.req.httpVersionMajor >= 2) {
body = String(code);
} else {
body = ctx.message || String(code);
}
if (!res.headersSent) {
ctx.type = 'text';
ctx.length = Buffer.byteLength(body);
Expand Down
12 changes: 12 additions & 0 deletions test/application/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('app.response', () => {
const app1 = new Koa();
app1.response.msg = 'hello';
const app2 = new Koa();
const app3 = new Koa();

it('should merge properties', () => {
app1.use((ctx, next) => {
Expand All @@ -31,4 +32,15 @@ describe('app.response', () => {
.get('/')
.expect(204);
});

it('should not include status message in body for http2', async () => {
app3.use((ctx, next) => {
ctx.req.httpVersionMajor = 2;
ctx.status = 404;
});
const response = await request(app3.listen())
.get('/')
.expect(404);
assert.equal(response.text, '404');
});
});

0 comments on commit 9905199

Please sign in to comment.