Skip to content

Content-Type parsing (MIME type parsing) #30

Closed
@annevk

Description

@annevk

I looked into MIME type parsing to figure out how to make progress with whatwg/fetch#579 and httpwg/http-core#33. However, it doesn't seem like there's much interoperability or good places to start.

For instance the following decodes as UTF-8 in Chrome and Firefox, but windows-1252 in Edge and Safari (inspired by http://searchfox.org/mozilla-central/rev/4b79f3b23aebb4080ea85e94351fd4046116a957/netwerk/base/nsURLHelper.cpp#957):

def main(request, response):
   response.headers.set("content-type", "text/html;charset=windows-1252,text/html;charset=utf-8")
   response.content = "\xC2\xB1"

Only Chrome and Firefox have a modicum of MIME type validation happening for data: URLs, but even that's rather limited and broken (e.g., unknown parameters get dropped, but image/gif;charset=x is fine).

It seems that anything here would have to be quite forgiving to maintain the status quo of not bailing if a MIME type is invalid (i.e.., treat text/html; as text/html and not as an error), but there's also quite some flexibility. And then there's the question of whether strings need to be simply passed through to Blob and such or if there should be some validation step to normalize input (Chrome and Firefox appear to lowercase all input there).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions