-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: net/http: add constant for content type #31572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
"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. Thoughts? |
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:
And because 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. |
Marked this last week as likely decline w/ call for last comments (#31572 (comment)). |
Sorry to post on a dead proposal, but I'd like understand more about why this is potentially an issue:
@cespare mentioned that the right hand side has to be parsed. How is a |
@ghostsquad it's not different in that regard. Whether the RHS is using a constant or a string literal, that code is a little broken. |
what's broken about it? |
|
Is it a good idea to add constants for content type of HTTP body like http.MethodPost in HTTP methods?
It might be
This changes will help us not typo, and get support from editors.
The text was updated successfully, but these errors were encountered: