Skip to content

Conversation

@mferrera
Copy link

@mferrera mferrera commented Nov 22, 2025

When a POST, PUT, or PATCH request is sent by Client.fetch without a payload an assert fails in sendBodiless as these HTTP methods are expected to have a body. However, the HTTP spec does not require them to have a body.

Some prior art on this ambiguity:

This change handles this scenario more gracefully and is consistent with how curl and other "fetch" abstractions do it. It mostly saves some dev tedium from handling this (suppose requests are crafted as user input to a zig executable).

$ curl -X POST http://localhost/echo/post 
{
  "args": {},
  "data": {}, # <--
  "files": {},
  "form": {},
  "headers": {
    "host": "localhost",
    "accept": "*/*",
    "accept-encoding": "gzip",
    "user-agent": "curl/8.7.1",
    "content-length": "0" # <--
  },
  "json": null,
  "url": "https://localhost/echo/post"
}
# null payload vs explicitly empty "" payload
$ curl -X POST -d "" http://localhost/echo/post
{
  "args": {},
  "data": "", # <--
  "files": {},
  "form": {},
  "headers": {
    "host": "localhost",
    "content-length": "0", # <--
    "accept-encoding": "gzip",
    "accept": "*/*",
    "user-agent": "curl/8.7.1",
    "content-type": "application/x-www-form-urlencoded"
  },
  "json": null,
  "url": "localhost/echo/post"
}

When a POST, PUT, or PATCH request is sent by Client.fetch without a
payload an assert fails in `sendBodiless` as these methods are expected
to have a body. However, the HTTP spec does not _require_ them to have a
body.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant