Skip to content

Response body not suppressed for HEAD requests #151

@VikramAditya33

Description

@VikramAditya33

Problem

When a handler sends a body on a HEAD request, the payload goes over the wire. HTTP spec (RFC 9110 §9.3.2) requires HEAD responses to have identical headers to GET but no body.

Current Behavior

@All()
allHandler(@Res() res: UwsResponse) {
  res.status(200).json({ handler: 'all' }); // Body sent even for HEAD
}

HEAD /all-test200 OK with JSON body in the response.

Root Cause

uWS is low-level and doesn't strip bodies for HEAD. Our adapter passes the handler's body straight through to uwsRes.end() without checking the request method.

Fix

In UwsResponse._sendInternal(), before calling uwsRes.end(body), check this.req?.method === 'HEAD'. If true, write headers but call uwsRes.end() with no body (or uwsRes.endWithoutBody(length)).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions