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
net/http: Question mark eaten from URL if no query parameters specified #13488
I'd like to understand the rationale behind this behaviour better.
Is that because the URL parser interpret the following from RFC 1738, section 3.3, that the "?" (question mark) is not part of the query string, but just separates it?
Does also the grammar in RFC 3986, Appendix A., indicate the "?" is not part of the actual query string?
If so, is my assumption correct that the
and, rightly, assumes the query component as undefined, hence superfluous?
BTW, I have filed very similar report to the Python Request library (psf/requests#2912).
This is the first I've heard of anybody caring about this. That's a pretty delicate API.
As background, we just basically kinda have no place to put this info:
u, err := url.Parse("http://example.com/foo") fmt.Printf("%#v, %v\n", u, err) u, err = url.Parse("http://example.com/foo?") fmt.Printf("%#v, %v\n", u, err) u, err = url.Parse("http://example.com/foo?a=b") fmt.Printf("%#v, %v\n", u, err)
I suppose we could special-case this with RawPath or Opaque, but I'd kinda rather not.
/cc @rsc for opinions.
I sympathise with your opinion.
And, I would understand the rationale.
Via those issue reports, I'm trying to learn what's vendors' take on distinguishing such URLs, as I'm struggling to draw any strict rule from the RFCs.
(Apology for lacking Go fu, I've just kickstarted myself to Go in this mloskot/http-url-test exercise.)
I received some pointers to further details in RFC 3986 (see Is question mark in URL part of query string?). In particular, 6.2.3. Scheme-Based Normalization which somewhat applies to this issue and the "question mark" handling. Quoting:
Where "examples above" refers to:
FYI, here is an example of API similar to the one in my issue above:
As people seem to agree, distinguishing these two is very likely a mistake. You say it is an internal API. I don't believe there are any examples of external APIs that demonstrate this problem, so we're not likely to make changes for a single non-public (and therefore not widely used) server.
It is still possible to create an HTTP request explicitly and then modify its URL to set the Opaque field to "/api/item.json?", if you must make calls to the server this way.
I don't think we should take any steps to help the situation unless there is evidence that it's a common problem for Go users. It seems like an isolated incident.
@rsc I understand your rationale and I don't aim to keep requesting any changes.
However, just to address some of your points
Amusingly, I just discovered that my Hunter Douglas Powerview blinds at home have this problem.
The blinds have a manual remote control that speaks some radio protocol, but there's also the "Powerview Hub" which puts the blinds on your wifi with an app. The Hub runs an HTTP server on port 80 speaking unauthenticated, unencrypted JSON.
But .... if you leave off the trailing question mark in certain queries, the hub crashes.
Another person who hit this: http://forum.universal-devices.com/topic/16538-hunter-douglas-powerview-control-with-isy/ who says:
I'm reopening this bug, not because we'll necessarily change anything, but because it was closed for lack for external examples.
I suppose we could, for Go 1.7, add a new field