Skip to content

HTTP/2: buffer body must have content length assertion when sending DELETE with a body #5027

@ChristianBoehlke

Description

@ChristianBoehlke

Bug Description

We upgraded to undici v8 which changed allowH2 to default to true. Some third-party APIs we integrate with require a body on DELETE requests (batch deletions). This started crashing with an uncaught AssertionError. Worked fine before v8 over HTTP/1.1.

writeH2 in client-h2.js nulls contentLength for methods that aren't POST/PUT/PATCH (!expectsPayload), but the body (converted to Buffer in the Request constructor) is still passed to writeBuffer, which asserts contentLength === body.byteLength (null === N).

Happy to open a PR with a fix.

Reproducible By

import { request } from 'undici';

await request('https://www.google.com', {
  method: 'DELETE',
  body: JSON.stringify({ ids: [1] }),
});

Expected Behavior

The request should be sent without an assertion error, as it does over HTTP/1.1.

Logs & Screenshots

AssertionError [ERR_ASSERTION]: buffer body must have content length
    at writeBuffer (undici/lib/dispatcher/client-h2.js:857:7)
    at writeBodyH2 (undici/lib/dispatcher/client-h2.js:792:7)
    at writeH2 (undici/lib/dispatcher/client-h2.js:675:5)

Environment

  • undici 8.1.0
  • Node.js v24.14.0
  • Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    H2Pull requests or issues related to HTTP/2bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions