FAQ
Hi folks,

In http://golang.org/src/pkg/net/http/request.go#L560
there is code that is dealing with the possibility of an
incoming 'standard' HTTP request (path only) or an
incoming proxy request (with a full URL specified).

I'm not understanding why the code then deletes the
Host record from req.Header map. Could someone
explain the reason for that operation on line 571?

    560 // RFC2616: Must treat 561 // GET /index.html HTTP/1.1 562 // Host: www.google.com 563 // and 564 // GET http://www.google.com/index.html HTTP/1.1 565 // Host: doesntmatter 566 // the same. In the second case, any Host line is ignored. 567 req.Host = req.URL.Host 568 if req.Host == "" { 569 req.Host = req.Header.get("Host") 570 } 571 delete(req.Header, "Host")

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Ross Light at Oct 3, 2013 at 10:15 pm
    I imagine that it is so that the user of net/http won't accidentally get a
    mismatch in the second case. It wouldn't make much sense for doesntmatter
    to stay in the Request struct.


    Ross Light | Software Engineer | light@google.com

    On Thu, Oct 3, 2013 at 2:57 PM, Jim Robinson wrote:

    Hi folks,

    In http://golang.org/src/pkg/net/http/request.go#L560
    there is code that is dealing with the possibility of an
    incoming 'standard' HTTP request (path only) or an
    incoming proxy request (with a full URL specified).

    I'm not understanding why the code then deletes the
    Host record from req.Header map. Could someone
    explain the reason for that operation on line 571?

    560 // RFC2616: Must treat 561 // GET /index.html HTTP/1.1 562 // Host: www.google.com 563 // and 564 // GET http://www.google.com/index.html HTTP/1.1 565 // Host: doesntmatter 566 // the same. In the second case, any Host line is ignored. 567 req.Host = req.URL.Host 568 if req.Host == "" { 569 req.Host = req.Header.get("Host") 570 } 571 delete(req.Header, "Host")

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedOct 3, '13 at 9:57p
activeOct 3, '13 at 10:15p
posts2
users2
websitegolang.org

2 users in discussion

Ross Light: 1 post Jim Robinson: 1 post

People

Translate

site design / logo © 2022 Grokbase