-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
net/http: allow multiple spaces between method and path in mux patterns #64910
Comments
"Be strict in what you accept" is the usual (contemporary) advice for interface design, and the API documentation is clear that it must be a single space. Perhaps @jba can offer more insight. |
I can't see any reason to enforce the single space, and aligning patterns seems like a good reason to drop it. |
This is consistent with HTTP itself, which also allows |
Seems fine to me since the verbs can't have spaces anyway. |
Is it? From https://datatracker.ietf.org/doc/html/rfc9112#name-request-line
|
Right, but the definition of SP in 2.2 Basic Rules also says:
which I took to mean that multiple spaces are allowed in the first line of the request. Perhaps I misread it, and this rule applies only to line continuations. Empirically some servers do permit multiple spaces---not that that is a reliable guide. $ { echo "GET / HTTP/1.1"; echo; } | nc google.com 80 | head -n 1
HTTP/1.1 200 OK |
This proposal has been added to the active column of the proposals project |
My gut says this is not a great idea, so I tried to back that up with some concrete cases where this will be a bad idea. And this is what I came up with:
- r.Handle("GET /my-route", handler1)
+ r.Handle("GET /my-route", handler1)
+ r.Handle("POST /my-route", handler2) |
Based on the discussion above, this proposal seems like a likely accept. The proposal is to accept multiple spaces in patterns like “GET /foo”. |
No change in consensus, so accepted. 🎉 The proposal is to accept multiple spaces in patterns like “GET /foo”. |
Based on the emoji votes of #64910 (comment) and #64910 (comment), is there really a consensus? |
@rsc in #64910 (comment):
The discussion above from @TheCoreMan was about
Thus, the upvotes are to highlight the cases where this proposal would be a bad idea, not to upvote the proposal. @rsc in #64910 (comment):
Where? There is no consensus I could find, |
In my opinion, it's not a bad idea if it doesn't slow down compilation parsing (would there be any way to test that?), and if gofmt and gofumpt apply the same rule to them at they apply for extra spaces in general. |
@earthboundkid may I ask why you downvoted #64910 (comment)? |
I don't think we should worry about parse performance at all. What matters is the performance for routing and serving HTTP requests, and that's not affected at all, as far as I can tell. Personally I find the argument at #64910 (comment) compelling in terms of allowing any whitespace. I'm not as worried in terms of consistent formatting noise, to be entirely honest - the same arguments could be made against the way Perhaps consider diff tools which support ignoring whitespace in some way. For example, GitHub already has a knob to ignore all whitespace changes like When it comes to the reactions or votes, my impression is they area helpful signal, but they shouldn't be used directly to measure consensus or reach a decision for a proposal. I personally value the opinion of the package maintainers above reactions, and in this case, both Jonathan and Russ (Neil hasn't commented) appear to lean in favor, and I'd tend to agree with them. |
If it's marginal, then there is nothing to worry about.
Same.
Understood. |
@Malix-off, you edited your comment, but before it said,
I think gofmt editing strings is a bad idea. I don't really understand the opposition to this proposal, tbh. Seems harmless to me. I don't think I will do it, but I also wouldn't change a codebase I encounter that does. |
Change https://go.dev/cl/565916 mentions this issue: |
Proposal Details
When testing the muxpatterns implementation which is landing in the stdlib Mux in Go 1.22, I was surprised to find that I could not add extra whitespace between the method and path. For instance, this does not work:
Allowing extra spaces is useful when you have many routes and want to keep the code neatly aligned, so it's easy to scan the routes visually. As a small example:
The text was updated successfully, but these errors were encountered: