Skip to content

Custom content-type header with FormData body warning is dead code #6067

@harrishancock

Description

@harrishancock

We have code which tries to warn the user when they create an HTTP message with a FormData body and a custom Content-Type header:

IoContext::current().logWarning(
"A FormData body was provided with a custom Content-Type header when constructing "
"a Request or Response object. This will prevent the recipient of the Request or "
"Response from being able to parse the body. Consider omitting the custom "
"Content-Type header.");

The warning is logged when this if condition is true:

} else if (MimeType::FORM_DATA == ct) {

The condition is guaranteed never to be true, because:

  • MimeType::FORM_DATA is a ConstMimeType (with content: multipart/form-data)
  • ct is a kj::String (with content: multipart/form-data; boundary=...)
  • ConstMimeType::operator==(kj::StringPtr) does not parse the string, but instead splits at the first / and compares everything before, then everything after:
    strcaseeq(subtype_, other.slice(slashPos + 1));
  • "form-data" != "form-data; boundary=...", so the if condition is always false

I would say there are two bugs here:

  1. ExtractedBody::contentType should preferably strongly typed, not just a kj::String
  2. ConstMimeType::operator==(kj::StringPtr) is a footgun, and should probably not exist -- comparing string MIME types should involve parsing them

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions