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: Question mark eaten from URL if no query parameters specified #13488
Comments
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) Currently says:
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: https://confluence.ucop.edu/display/Curation/ARK
|
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. What about 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 |
CL https://golang.org/cl/19931 mentions this issue. |
It looks like this improperly parses URLs if the query string ends in |
@bjkail, please file a new bug and reference this one. |
What version of Go are you using (go version)?
What operating system and processor architecture are you using?
Windows 8.1 Pro (64-bit)
What did you do?
There is an (internal) API for which these two URLs identifie two different resources:
A.
http://server.com/api/item.json
B.
http://server.com/api/item.json?
The second URL is indeed with question mark, but without query parameters.
I make HTTP GET request using the resource B:
What did you expect to see?
I expect to receive representation of the resource B.
What did you see instead?
I received representation of the resource A.
So,
net/http
somewhat eats-or-skips the question mark if there are no query parameters.BTW, I'm seeing the same behaviour while using https://github.com/parnurzeal/gorequest package.
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
net/http
package decomposes and recomposes URL likehttp://server.com/item.json?
applying the suggested (de|re)composition algorithm, i.e.:and, rightly, assumes the query component as undefined, hence superfluous?
BTW, I have filed very similar report to the Python Request library (kennethreitz/requests#2912).
I have also tested the requests using number of HTTP packages for different programming languages, here https://github.com/mloskot/http-url-test.
To summary, 4 of 14 packages eat-or-skip the trailing question mark, namely:
The text was updated successfully, but these errors were encountered: