From b9702967ee6ce84303296b111f596fefab3a60a9 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Sat, 31 Oct 2015 15:23:52 +0000 Subject: libgo: Update from Go 1.5 to Go 1.5.1. Reviewed-on: https://go-review.googlesource.com/16527 From-SVN: r229624 --- libgo/go/net/cgo_solaris.go | 2 +- libgo/go/net/http/httputil/reverseproxy.go | 5 +++- libgo/go/net/http/httputil/reverseproxy_test.go | 39 +++++++++++++++++++++++++ libgo/go/net/lookup.go | 3 ++ libgo/go/net/port_test.go | 2 ++ 5 files changed, 49 insertions(+), 2 deletions(-) (limited to 'libgo/go/net') diff --git a/libgo/go/net/cgo_solaris.go b/libgo/go/net/cgo_solaris.go index c5a7a35..05811c6 100644 --- a/libgo/go/net/cgo_solaris.go +++ b/libgo/go/net/cgo_solaris.go @@ -7,7 +7,7 @@ package net /* -#cgo LDFLAGS: -lsocket -lnsl +#cgo LDFLAGS: -lsocket -lnsl -lsendfile #include */ diff --git a/libgo/go/net/http/httputil/reverseproxy.go b/libgo/go/net/http/httputil/reverseproxy.go index 3b7a184..c8e1132 100644 --- a/libgo/go/net/http/httputil/reverseproxy.go +++ b/libgo/go/net/http/httputil/reverseproxy.go @@ -105,7 +105,7 @@ type requestCanceler interface { } type runOnFirstRead struct { - io.Reader + io.Reader // optional; nil means empty body fn func() // Run before first Read, then set to nil } @@ -115,6 +115,9 @@ func (c *runOnFirstRead) Read(bs []byte) (int, error) { c.fn() c.fn = nil } + if c.Reader == nil { + return 0, io.EOF + } return c.Reader.Read(bs) } diff --git a/libgo/go/net/http/httputil/reverseproxy_test.go b/libgo/go/net/http/httputil/reverseproxy_test.go index 25947e6..80a26ab 100644 --- a/libgo/go/net/http/httputil/reverseproxy_test.go +++ b/libgo/go/net/http/httputil/reverseproxy_test.go @@ -7,6 +7,7 @@ package httputil import ( + "bufio" "io/ioutil" "log" "net/http" @@ -281,3 +282,41 @@ func TestReverseProxyCancellation(t *testing.T) { t.Fatal("DefaultClient.Do() returned nil error") } } + +func req(t *testing.T, v string) *http.Request { + req, err := http.ReadRequest(bufio.NewReader(strings.NewReader(v))) + if err != nil { + t.Fatal(err) + } + return req +} + +// Issue 12344 +func TestNilBody(t *testing.T) { + backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Write([]byte("hi")) + })) + defer backend.Close() + + frontend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + backURL, _ := url.Parse(backend.URL) + rp := NewSingleHostReverseProxy(backURL) + r := req(t, "GET / HTTP/1.0\r\n\r\n") + r.Body = nil // this accidentally worked in Go 1.4 and below, so keep it working + rp.ServeHTTP(w, r) + })) + defer frontend.Close() + + res, err := http.Get(frontend.URL) + if err != nil { + t.Fatal(err) + } + defer res.Body.Close() + slurp, err := ioutil.ReadAll(res.Body) + if err != nil { + t.Fatal(err) + } + if string(slurp) != "hi" { + t.Errorf("Got %q; want %q", slurp, "hi") + } +} diff --git a/libgo/go/net/lookup.go b/libgo/go/net/lookup.go index a7ceee8..9008322 100644 --- a/libgo/go/net/lookup.go +++ b/libgo/go/net/lookup.go @@ -123,6 +123,9 @@ func lookupIPDeadline(host string, deadline time.Time) (addrs []IPAddr, err erro // LookupPort looks up the port for the given network and service. func LookupPort(network, service string) (port int, err error) { + if n, i, ok := dtoi(service, 0); ok && i == len(service) { + return n, nil + } return lookupPort(network, service) } diff --git a/libgo/go/net/port_test.go b/libgo/go/net/port_test.go index 2dacd97..258a5bd 100644 --- a/libgo/go/net/port_test.go +++ b/libgo/go/net/port_test.go @@ -27,6 +27,7 @@ var portTests = []struct { {"tcp", "time", 37, true}, {"tcp", "domain", 53, true}, {"tcp", "finger", 79, true}, + {"tcp", "42", 42, true}, {"udp", "echo", 7, true}, {"udp", "tftp", 69, true}, @@ -36,6 +37,7 @@ var portTests = []struct { {"udp", "ntp", 123, true}, {"udp", "snmp", 161, true}, {"udp", "syslog", 514, true}, + {"udp", "42", 42, true}, {"--badnet--", "zzz", 0, false}, {"tcp", "--badport--", 0, false}, -- cgit v1.1