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/httputil: proxy does not fix Host #2746

Closed
rsc opened this issue Jan 20, 2012 · 4 comments
Closed

net/http/httputil: proxy does not fix Host #2746

rsc opened this issue Jan 20, 2012 · 4 comments
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Jan 20, 2012

package main

import (
    "log"
    "net/http"
    "net/http/httputil"
    "net/url"
)

func main() {
    u, _ := url.Parse("http://localhost:8002/";)
    go http.ListenAndServe(":8002", http.HandlerFunc(echo))
    log.Fatal(http.ListenAndServe(":8001", httputil.NewSingleHostReverseProxy(u)))
}

func echo(w http.ResponseWriter, req *http.Request) {
    w.Header().Set("Content-Type", "text/plain")
    req.Write(w)
}

There is an echo server running on http://localhost:8002/
that prints the request back, and a proxy on http://localhost:8001/
that proxies to http://localhost:8002/.

I expect that loading either port should be the same, but they're not.

coma=; curl http://localhost:8001/
GET / HTTP/1.1
Host: localhost:8001
User-Agent: curl/7.21.3 (x86_64-pc-linux-gnu) libcurl/7.21.3 OpenSSL/0.9.8o zlib/1.2.3.4
libidn/1.18
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: ::1

coma=; curl http://localhost:8002/
GET / HTTP/1.1
Host: localhost:8002
User-Agent: curl/7.21.3 (x86_64-pc-linux-gnu) libcurl/7.21.3 OpenSSL/0.9.8o zlib/1.2.3.4
libidn/1.18
Accept: */*

coma=; 

Remember that the 8002 server is echoing back the request
in both cases.  In the proxying (first) case, the proxied
request still says Host: localhost:8001.  That seems wrong.
@rsc
Copy link
Contributor Author

rsc commented Jan 20, 2012

Comment 1:

Owner changed to @bradfitz.

Status changed to New.

@rsc
Copy link
Contributor Author

rsc commented Jan 24, 2012

Comment 2:

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

Owner changed to builder@golang.org.

Status changed to Accepted.

@bradfitz
Copy link
Contributor

Comment 3:

It is called a *reverse* proxy.  In that direction, Host is typically not fixed up. 
Reverse proxies are used to take requests from the Internet and balance them over many
backend servers, which will want to know the original host.
I don't know the context here, but it sounds like you want an outbound proxy.
Hopefully I'm using the right terminology, if there are naming rules for any of this.

@rsc
Copy link
Contributor Author

rsc commented Jan 25, 2012

Comment 4:

Status changed to Retracted.

@rsc rsc added this to the Go1 milestone Apr 10, 2015
@rsc rsc removed the priority-go1 label Apr 10, 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.
Projects
None yet
Development

No branches or pull requests

3 participants