fix: Status message is not supported on HTTP/2 (#1264)
This commit is contained in:
parent
71aaa29591
commit
99051992a9
2 changed files with 17 additions and 1 deletions
|
@ -222,7 +222,11 @@ function respond(ctx) {
|
|||
|
||||
// status body
|
||||
if (null == body) {
|
||||
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);
|
||||
|
|
|
@ -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) => {
|
||||
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue