summaryrefslogtreecommitdiff
path: root/libgo/go/net
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2013-11-27 01:05:38 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2013-11-27 01:05:38 +0000
commit5b15b0fbc7321727ec87cc800c383ba785f76692 (patch)
treea639e5c4b06bb7971b24112a25fdae25a1b3d863 /libgo/go/net
parente93548ee7f2537b300aafad54418df4f6d5d7433 (diff)
downloadgcc-5b15b0fbc7321727ec87cc800c383ba785f76692.tar.gz
libgo: Update to current Go library.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@205426 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/net')
-rw-r--r--libgo/go/net/hosts_test.go13
-rw-r--r--libgo/go/net/http/httputil/dump.go28
-rw-r--r--libgo/go/net/http/httputil/dump_test.go30
-rw-r--r--libgo/go/net/parse.go2
-rw-r--r--libgo/go/net/testdata/hosts_singleline1
-rw-r--r--libgo/go/net/textproto/reader.go9
-rw-r--r--libgo/go/net/textproto/reader_test.go4
-rw-r--r--libgo/go/net/url/url.go4
8 files changed, 79 insertions, 12 deletions
diff --git a/libgo/go/net/hosts_test.go b/libgo/go/net/hosts_test.go
index 064e7e43282..b07ed0baa94 100644
--- a/libgo/go/net/hosts_test.go
+++ b/libgo/go/net/hosts_test.go
@@ -53,6 +53,19 @@ func TestLookupStaticHost(t *testing.T) {
hostsPath = p
}
+// https://code.google.com/p/go/issues/detail?id=6646
+func TestSingleLineHostsFile(t *testing.T) {
+ p := hostsPath
+ hostsPath = "testdata/hosts_singleline"
+
+ ips := lookupStaticHost("odin")
+ if len(ips) != 1 || ips[0] != "127.0.0.2" {
+ t.Errorf("lookupStaticHost = %v, want %v", ips, []string{"127.0.0.2"})
+ }
+
+ hostsPath = p
+}
+
func TestLookupHost(t *testing.T) {
// Can't depend on this to return anything in particular,
// but if it does return something, make sure it doesn't
diff --git a/libgo/go/net/http/httputil/dump.go b/libgo/go/net/http/httputil/dump.go
index 0b003566165..265499fb00d 100644
--- a/libgo/go/net/http/httputil/dump.go
+++ b/libgo/go/net/http/httputil/dump.go
@@ -45,13 +45,27 @@ func (c *dumpConn) SetDeadline(t time.Time) error { return nil }
func (c *dumpConn) SetReadDeadline(t time.Time) error { return nil }
func (c *dumpConn) SetWriteDeadline(t time.Time) error { return nil }
+type neverEnding byte
+
+func (b neverEnding) Read(p []byte) (n int, err error) {
+ for i := range p {
+ p[i] = byte(b)
+ }
+ return len(p), nil
+}
+
// DumpRequestOut is like DumpRequest but includes
// headers that the standard http.Transport adds,
// such as User-Agent.
func DumpRequestOut(req *http.Request, body bool) ([]byte, error) {
save := req.Body
+ dummyBody := false
if !body || req.Body == nil {
req.Body = nil
+ if req.ContentLength != 0 {
+ req.Body = ioutil.NopCloser(io.LimitReader(neverEnding('x'), req.ContentLength))
+ dummyBody = true
+ }
} else {
var err error
save, req.Body, err = drainBody(req.Body)
@@ -99,7 +113,19 @@ func DumpRequestOut(req *http.Request, body bool) ([]byte, error) {
if err != nil {
return nil, err
}
- return buf.Bytes(), nil
+ dump := buf.Bytes()
+
+ // If we used a dummy body above, remove it now.
+ // TODO: if the req.ContentLength is large, we allocate memory
+ // unnecessarily just to slice it off here. But this is just
+ // a debug function, so this is acceptable for now. We could
+ // discard the body earlier if this matters.
+ if dummyBody {
+ if i := bytes.Index(dump, []byte("\r\n\r\n")); i >= 0 {
+ dump = dump[:i+4]
+ }
+ }
+ return dump, nil
}
// delegateReader is a reader that delegates to another reader,
diff --git a/libgo/go/net/http/httputil/dump_test.go b/libgo/go/net/http/httputil/dump_test.go
index 3e87c27bc36..987a820487d 100644
--- a/libgo/go/net/http/httputil/dump_test.go
+++ b/libgo/go/net/http/httputil/dump_test.go
@@ -20,6 +20,7 @@ type dumpTest struct {
WantDump string
WantDumpOut string
+ NoBody bool // if true, set DumpRequest{,Out} body to false
}
var dumpTests = []dumpTest{
@@ -83,6 +84,31 @@ var dumpTests = []dumpTest{
"User-Agent: Go 1.1 package http\r\n" +
"Accept-Encoding: gzip\r\n\r\n",
},
+
+ // Request with Body, but Dump requested without it.
+ {
+ Req: http.Request{
+ Method: "POST",
+ URL: &url.URL{
+ Scheme: "http",
+ Host: "post.tld",
+ Path: "/",
+ },
+ ContentLength: 6,
+ ProtoMajor: 1,
+ ProtoMinor: 1,
+ },
+
+ Body: []byte("abcdef"),
+
+ WantDumpOut: "POST / HTTP/1.1\r\n" +
+ "Host: post.tld\r\n" +
+ "User-Agent: Go 1.1 package http\r\n" +
+ "Content-Length: 6\r\n" +
+ "Accept-Encoding: gzip\r\n\r\n",
+
+ NoBody: true,
+ },
}
func TestDumpRequest(t *testing.T) {
@@ -105,7 +131,7 @@ func TestDumpRequest(t *testing.T) {
if tt.WantDump != "" {
setBody()
- dump, err := DumpRequest(&tt.Req, true)
+ dump, err := DumpRequest(&tt.Req, !tt.NoBody)
if err != nil {
t.Errorf("DumpRequest #%d: %s", i, err)
continue
@@ -118,7 +144,7 @@ func TestDumpRequest(t *testing.T) {
if tt.WantDumpOut != "" {
setBody()
- dump, err := DumpRequestOut(&tt.Req, true)
+ dump, err := DumpRequestOut(&tt.Req, !tt.NoBody)
if err != nil {
t.Errorf("DumpRequestOut #%d: %s", i, err)
continue
diff --git a/libgo/go/net/parse.go b/libgo/go/net/parse.go
index 7c87b42f6d9..6056de248e0 100644
--- a/libgo/go/net/parse.go
+++ b/libgo/go/net/parse.go
@@ -54,7 +54,7 @@ func (f *file) readLine() (s string, ok bool) {
if n >= 0 {
f.data = f.data[0 : ln+n]
}
- if err == io.EOF {
+ if err == io.EOF || err == io.ErrUnexpectedEOF {
f.atEOF = true
}
}
diff --git a/libgo/go/net/testdata/hosts_singleline b/libgo/go/net/testdata/hosts_singleline
new file mode 100644
index 00000000000..5f5f74a3fad
--- /dev/null
+++ b/libgo/go/net/testdata/hosts_singleline
@@ -0,0 +1 @@
+127.0.0.2 odin \ No newline at end of file
diff --git a/libgo/go/net/textproto/reader.go b/libgo/go/net/textproto/reader.go
index 56ece5b087c..b0c07413c19 100644
--- a/libgo/go/net/textproto/reader.go
+++ b/libgo/go/net/textproto/reader.go
@@ -574,13 +574,10 @@ func canonicalMIMEHeaderKey(a []byte) string {
// and upper case after each dash.
// (Host, User-Agent, If-Modified-Since).
// MIME headers are ASCII only, so no Unicode issues.
- if a[i] == ' ' {
- a[i] = '-'
- upper = true
- continue
- }
c := a[i]
- if upper && 'a' <= c && c <= 'z' {
+ if c == ' ' {
+ c = '-'
+ } else if upper && 'a' <= c && c <= 'z' {
c -= toLower
} else if !upper && 'A' <= c && c <= 'Z' {
c += toLower
diff --git a/libgo/go/net/textproto/reader_test.go b/libgo/go/net/textproto/reader_test.go
index f27042d4e9d..cc12912b634 100644
--- a/libgo/go/net/textproto/reader_test.go
+++ b/libgo/go/net/textproto/reader_test.go
@@ -25,6 +25,10 @@ var canonicalHeaderKeyTests = []canonicalHeaderKeyTest{
{"user-agent", "User-Agent"},
{"USER-AGENT", "User-Agent"},
{"üser-agenT", "üser-Agent"}, // non-ASCII unchanged
+
+ // This caused a panic due to mishandling of a space:
+ {"C Ontent-Transfer-Encoding", "C-Ontent-Transfer-Encoding"},
+ {"foo bar", "Foo-Bar"},
}
func TestCanonicalMIMEHeaderKey(t *testing.T) {
diff --git a/libgo/go/net/url/url.go b/libgo/go/net/url/url.go
index 597cb51c883..3b3787202b7 100644
--- a/libgo/go/net/url/url.go
+++ b/libgo/go/net/url/url.go
@@ -558,8 +558,8 @@ func parseQuery(m Values, query string) (err error) {
return err
}
-// Encode encodes the values into ``URL encoded'' form.
-// e.g. "foo=bar&bar=baz"
+// Encode encodes the values into ``URL encoded'' form
+// ("bar=baz&foo=quux") sorted by key.
func (v Values) Encode() string {
if v == nil {
return ""