mirror of
https://github.com/golang/go
synced 2024-11-26 21:11:57 -07:00
net/http/cgi: Correctly pass down the REMOTE_PORT value for CGI requests.
Currently when we get a CGI or FCGI request, the remote port of the client is hard coded to zero, despite nearly every webserver passing down the REMOTE_PORT variable. This was likely originally excluded because the CGI RFC (rfc3875) does not mention anything about the remote port of the client. However every webserver tested does pass REMOTE_PORT down. This includes Apache 2.2, Apache 2.4, nginx and lighttpd. Fixes #8351 Change-Id: I4c6366cb39f0ccc05e038bd31d85f93b76e8d0c8 Reviewed-on: https://go-review.googlesource.com/1750 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
209dd4cdc1
commit
3ffc9756d1
@ -132,9 +132,9 @@ func RequestFromMap(params map[string]string) (*http.Request, error) {
|
||||
}
|
||||
|
||||
// Request.RemoteAddr has its port set by Go's standard http
|
||||
// server, so we do here too. We don't have one, though, so we
|
||||
// use a dummy one.
|
||||
r.RemoteAddr = net.JoinHostPort(params["REMOTE_ADDR"], "0")
|
||||
// server, so we do here too.
|
||||
remotePort, _ := strconv.Atoi(params["REMOTE_PORT"]) // zero if unset or invalid
|
||||
r.RemoteAddr = net.JoinHostPort(params["REMOTE_ADDR"], strconv.Itoa(remotePort))
|
||||
|
||||
return r, nil
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ func TestRequest(t *testing.T) {
|
||||
"CONTENT_LENGTH": "123",
|
||||
"CONTENT_TYPE": "text/xml",
|
||||
"REMOTE_ADDR": "5.6.7.8",
|
||||
"REMOTE_PORT": "54321",
|
||||
}
|
||||
req, err := RequestFromMap(env)
|
||||
if err != nil {
|
||||
@ -60,7 +61,7 @@ func TestRequest(t *testing.T) {
|
||||
if req.TLS != nil {
|
||||
t.Errorf("expected nil TLS")
|
||||
}
|
||||
if e, g := "5.6.7.8:0", req.RemoteAddr; e != g {
|
||||
if e, g := "5.6.7.8:54321", req.RemoteAddr; e != g {
|
||||
t.Errorf("RemoteAddr: got %q; want %q", g, e)
|
||||
}
|
||||
}
|
||||
@ -129,3 +130,21 @@ func TestRequestWithoutRequestURI(t *testing.T) {
|
||||
t.Errorf("URL = %q; want %q", g, e)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequestWithoutRemotePort(t *testing.T) {
|
||||
env := map[string]string{
|
||||
"SERVER_PROTOCOL": "HTTP/1.1",
|
||||
"HTTP_HOST": "example.com",
|
||||
"REQUEST_METHOD": "GET",
|
||||
"REQUEST_URI": "/path?a=b",
|
||||
"CONTENT_LENGTH": "123",
|
||||
"REMOTE_ADDR": "5.6.7.8",
|
||||
}
|
||||
req, err := RequestFromMap(env)
|
||||
if err != nil {
|
||||
t.Fatalf("RequestFromMap: %v", err)
|
||||
}
|
||||
if e, g := "5.6.7.8:0", req.RemoteAddr; e != g {
|
||||
t.Errorf("RemoteAddr: got %q; want %q", g, e)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user