How to sent Content-Length on a HEAD response #1827
-
I am trying to sent the Content-Length header of a HEAD method response but it seems like Koa it automatically removing the header when the body is set to export async function head(ctx, next) {
ctx.set('Content-Length', Buffer.from(JSON.stringify(ctx.body)).length);
ctx.body = null;
await next();
} Note: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
try setting the content length after setting the body |
Beta Was this translation helpful? Give feedback.
-
additionally, since you already set the body, |
Beta Was this translation helpful? Give feedback.
additionally, since you already set the body,
koa
will know not to send it on HEAD requests, so you actually don't need to do anything