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: |
Answered by
jonathanong
Apr 6, 2025
Replies: 2 comments
|
try setting the content length after setting the body |
0 replies
|
additionally, since you already set the body, |
0 replies
Answer selected by
jonathanong
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
additionally, since you already set the body,
koawill know not to send it on HEAD requests, so you actually don't need to do anything