Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
proposal: net/http: add constant for content type #31572
"ContentTypeForm" would be a shorter, better name. Should there be a few of the most common ones here?
It would be unfortunate if this leads to more requests to add more, like MethodPost etc have.
This is already an all-too-common mistake and I think that adding the constants would, if anything, make it a little worse.
Before, the issue with code like
was that the left side needed to be parsed to get the media type value out. With
both sides need to be parsed. Or worse, with
it happens to work now, but depends on ContentTypeJSON being a media type value without optional parameters.
Because these constants can only be effectively used for setting the Content-Type and not retrieving it, I don't think we should add them. If we do add API for common Content-Types, I think it ought to be opaque types that can be used for both setting and retrieving.
@bradfitz Have you thought about Content-Type usability? I don't see any references to Content-Type in the discussion around http(client) v2.
I'd like to see a new (string-backed) type for media types. Then we could do:
A nice place for this type might be the
I'd rather not duplicate it with a newer version in
@bradfitz suggested something quite different from the original proposal, and no one has replied. It sounds like we should decline this proposal as too little impact / not clear enough solution.
Will leave this open for a week for any final comments; if not, will decline.
I think @bradfitz's proposal would be an improvement over the status quo, and I would use it in a bunch of places.
However, I'd still prefer an API which helps with both common content-type operations: setting a response's content-type and checking a request's content-type. The ideas in this issue only address the former.
That should probably be a different proposal, though, if someone comes up with a concrete suggestion.