Skip to content
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: document fields set in Request.URL in handler #3805

Closed
gopherbot opened this issue Jul 6, 2012 · 9 comments
Closed

net/http: document fields set in Request.URL in handler #3805

gopherbot opened this issue Jul 6, 2012 · 9 comments
Labels
FrozenDueToAge Suggested Issues that may be good for new contributors looking for work to do.
Milestone

Comments

@gopherbot
Copy link

by kelwert@mtu.edu:

I'm not entirely sure which of these should be missing, but, when using
http.ListenAndServe, it appears, that in the URL field, a good number of the fields are
missing that should be set.

r.URL.Opaque is empty
r.URL.User is nil, even when a username is passed, though I'm not 100% sure with this one
r.URL.Host is not set. This is really just an inconvenience. It can be hacked around
with r.URL.Host = r.Host
r.URL.Fragment is empty
r.URL.Scheme is empty.

These were tested using localhost, so I could understand if Host wasn't set (though, I
think it probably should be), but Scheme should really be set.

This is relatively simple to reproduce. Just set up a handler for http.ListenAndServe
and check what's set in r.URL.
@gopherbot
Copy link
Author

Comment 1 by kelwert@mtu.edu:

Notes: This appears to be the case in stable and from the tip.

@davecheney
Copy link
Contributor

Comment 2:

Some additional details:
lucky(~/src) go run http.go &
[1] 2170
lucky(~/src) % curl http://alice:bob@lucky.local:8080/foo/bar?baz#flobble
&url.URL{Scheme:"", Opaque:"", User:(*url.Userinfo)(nil), Host:"", Path:"/foo/bar",
RawQuery:"baz", Fragment:""}
&http.Request{Method:"GET", URL:(*url.URL)(0xf8400683f0), Proto:"HTTP/1.1",
ProtoMajor:1, ProtoMinor:1, Header:http.Header{"Authorization":[]string{"Basic
YWxpY2U6Ym9i"}, "User-Agent":[]string{"curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0
OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3"}, "Accept":[]string{"*/*"}},
Body:(*http.body)(0xf84007a740), ContentLength:0, TransferEncoding:[]string(nil),
Close:false, Host:"lucky.local:8080", Form:url.Values(nil), PostForm:url.Values(nil),
MultipartForm:(*multipart.Form)(nil), Trailer:http.Header(nil),
RemoteAddr:"192.168.1.25:56773", RequestURI:"/foo/bar?baz",
TLS:(*tls.ConnectionState)(nil)}

Attachments:

  1. http.go (246 bytes)

@bradfitz
Copy link
Contributor

Comment 3:

Fragments are never sent in HTTP.  They're purely a local browser concept.
Opaque and Fragment should not be set. Scheme isn't necessarily known... the HTTP
package just uses a listener.  It doesn't know the details of how a connection was made.
 Although I'm sure we could hack it to make it work for the common two types.

@gopherbot
Copy link
Author

Comment 4 by kelwert@mtu.edu:

Shouldn't Host be set though?

@rsc
Copy link
Contributor

rsc commented Sep 12, 2012

Comment 6:

This seems to me mainly a doc fix.
If the request said GET /foo then r.URL.Host will be empty.
If the request said GET http://you.com/foo then r.URL.Host will be "you.com". But that's
only common in proxies.
r.Host is the convenience, the effective host regardless of the request form. r.URL
tells you what was sent in the GET line.

Labels changed: added priority-later, removed priority-triage.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Sep 12, 2012

Comment 7:

Labels changed: added go1.1.

@rsc
Copy link
Contributor

rsc commented Dec 10, 2012

Comment 8:

Labels changed: added size-s.

@rsc
Copy link
Contributor

rsc commented Dec 10, 2012

Comment 9:

Labels changed: added suggested.

@rsc
Copy link
Contributor

rsc commented Jan 2, 2013

Comment 10:

This issue was closed by revision 948f0b7.

Status changed to Fixed.

@gopherbot gopherbot added fixed Suggested Issues that may be good for new contributors looking for work to do. labels Jan 2, 2013
@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Suggested Issues that may be good for new contributors looking for work to do.
Projects
None yet
Development

No branches or pull requests

4 participants