diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-06-25 16:20:03 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-06-25 16:20:03 +0000 |
commit | 4b786d35e0af0c254988199551709abef06b925e (patch) | |
tree | 5dfe28c3f573ae57b971ed4d9a1c99a76f0a70c4 /libgo/go/net | |
parent | 2e6c5d723ff7407704f2cbd343383991b498fb5b (diff) | |
download | gcc-4b786d35e0af0c254988199551709abef06b925e.tar.gz |
libgo: Update to Go 1.0.2 release.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@188943 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/net')
-rw-r--r-- | libgo/go/net/file.go | 4 | ||||
-rw-r--r-- | libgo/go/net/http/client.go | 5 | ||||
-rw-r--r-- | libgo/go/net/http/client_test.go | 25 | ||||
-rw-r--r-- | libgo/go/net/http/proxy_test.go | 30 | ||||
-rw-r--r-- | libgo/go/net/http/response.go | 9 | ||||
-rw-r--r-- | libgo/go/net/http/response_test.go | 15 | ||||
-rw-r--r-- | libgo/go/net/http/server.go | 2 | ||||
-rw-r--r-- | libgo/go/net/http/transfer.go | 6 | ||||
-rw-r--r-- | libgo/go/net/http/transport.go | 6 | ||||
-rw-r--r-- | libgo/go/net/mail/message.go | 11 | ||||
-rw-r--r-- | libgo/go/net/mail/message_test.go | 5 | ||||
-rw-r--r-- | libgo/go/net/url/url.go | 5 | ||||
-rw-r--r-- | libgo/go/net/url/url_test.go | 31 |
13 files changed, 138 insertions, 16 deletions
diff --git a/libgo/go/net/file.go b/libgo/go/net/file.go index c95d16d64e7..fc6c6fad8e1 100644 --- a/libgo/go/net/file.go +++ b/libgo/go/net/file.go @@ -89,8 +89,8 @@ func FileConn(f *os.File) (c Conn, err error) { // FileListener returns a copy of the network listener corresponding // to the open file f. It is the caller's responsibility to close l -// when finished. Closing c does not affect l, and closing l does not -// affect c. +// when finished. Closing l does not affect f, and closing f does not +// affect l. func FileListener(f *os.File) (l Listener, err error) { fd, err := newFileFD(f) if err != nil { diff --git a/libgo/go/net/http/client.go b/libgo/go/net/http/client.go index 5d450258bd3..54564e0989e 100644 --- a/libgo/go/net/http/client.go +++ b/libgo/go/net/http/client.go @@ -278,6 +278,11 @@ func (c *Client) Post(url string, bodyType string, body io.Reader) (r *Response, return nil, err } req.Header.Set("Content-Type", bodyType) + if c.Jar != nil { + for _, cookie := range c.Jar.Cookies(req.URL) { + req.AddCookie(cookie) + } + } r, err = send(req, c.Transport) if err == nil && c.Jar != nil { c.Jar.SetCookies(req.URL, r.Cookies()) diff --git a/libgo/go/net/http/client_test.go b/libgo/go/net/http/client_test.go index e00b62e590a..9b4261b9f61 100644 --- a/libgo/go/net/http/client_test.go +++ b/libgo/go/net/http/client_test.go @@ -256,6 +256,31 @@ var echoCookiesRedirectHandler = HandlerFunc(func(w ResponseWriter, r *Request) } }) +func TestClientSendsCookieFromJar(t *testing.T) { + tr := &recordingTransport{} + client := &Client{Transport: tr} + client.Jar = &TestJar{perURL: make(map[string][]*Cookie)} + us := "http://dummy.faketld/" + u, _ := url.Parse(us) + client.Jar.SetCookies(u, expectedCookies) + + client.Get(us) // Note: doesn't hit network + matchReturnedCookies(t, expectedCookies, tr.req.Cookies()) + + client.Head(us) // Note: doesn't hit network + matchReturnedCookies(t, expectedCookies, tr.req.Cookies()) + + client.Post(us, "text/plain", strings.NewReader("body")) // Note: doesn't hit network + matchReturnedCookies(t, expectedCookies, tr.req.Cookies()) + + client.PostForm(us, url.Values{}) // Note: doesn't hit network + matchReturnedCookies(t, expectedCookies, tr.req.Cookies()) + + req, _ := NewRequest("GET", us, nil) + client.Do(req) // Note: doesn't hit network + matchReturnedCookies(t, expectedCookies, tr.req.Cookies()) +} + // Just enough correctness for our redirect tests. Uses the URL.Host as the // scope of all cookies. type TestJar struct { diff --git a/libgo/go/net/http/proxy_test.go b/libgo/go/net/http/proxy_test.go index 9b320b3aa5b..5ecffaface9 100644 --- a/libgo/go/net/http/proxy_test.go +++ b/libgo/go/net/http/proxy_test.go @@ -5,6 +5,7 @@ package http import ( + "net/url" "os" "testing" ) @@ -46,3 +47,32 @@ func TestUseProxy(t *testing.T) { } } } + +var cacheKeysTests = []struct { + proxy string + scheme string + addr string + key string +}{ + {"", "http", "foo.com", "|http|foo.com"}, + {"", "https", "foo.com", "|https|foo.com"}, + {"http://foo.com", "http", "foo.com", "http://foo.com|http|"}, + {"http://foo.com", "https", "foo.com", "http://foo.com|https|foo.com"}, +} + +func TestCacheKeys(t *testing.T) { + for _, tt := range cacheKeysTests { + var proxy *url.URL + if tt.proxy != "" { + u, err := url.Parse(tt.proxy) + if err != nil { + t.Fatal(err) + } + proxy = u + } + cm := connectMethod{proxy, tt.scheme, tt.addr} + if cm.String() != tt.key { + t.Fatalf("{%q, %q, %q} cache key %q; want %q", tt.proxy, tt.scheme, tt.addr, cm.String(), tt.key) + } + } +} diff --git a/libgo/go/net/http/response.go b/libgo/go/net/http/response.go index b7902209786..945ecd8a4b0 100644 --- a/libgo/go/net/http/response.go +++ b/libgo/go/net/http/response.go @@ -202,9 +202,12 @@ func (r *Response) Write(w io.Writer) error { text = "status code " + strconv.Itoa(r.StatusCode) } } - io.WriteString(w, "HTTP/"+strconv.Itoa(r.ProtoMajor)+".") - io.WriteString(w, strconv.Itoa(r.ProtoMinor)+" ") - io.WriteString(w, strconv.Itoa(r.StatusCode)+" "+text+"\r\n") + protoMajor, protoMinor := strconv.Itoa(r.ProtoMajor), strconv.Itoa(r.ProtoMinor) + statusCode := strconv.Itoa(r.StatusCode) + " " + if strings.HasPrefix(text, statusCode) { + text = text[len(statusCode):] + } + io.WriteString(w, "HTTP/"+protoMajor+"."+protoMinor+" "+statusCode+text+"\r\n") // Process Body,ContentLength,Close,Trailer tw, err := newTransferWriter(r) diff --git a/libgo/go/net/http/response_test.go b/libgo/go/net/http/response_test.go index 165ec3624a4..6eed4887ddc 100644 --- a/libgo/go/net/http/response_test.go +++ b/libgo/go/net/http/response_test.go @@ -14,6 +14,7 @@ import ( "io/ioutil" "net/url" "reflect" + "strings" "testing" ) @@ -444,3 +445,17 @@ func TestLocationResponse(t *testing.T) { } } } + +func TestResponseStatusStutter(t *testing.T) { + r := &Response{ + Status: "123 some status", + StatusCode: 123, + ProtoMajor: 1, + ProtoMinor: 3, + } + var buf bytes.Buffer + r.Write(&buf) + if strings.Contains(buf.String(), "123 123") { + t.Errorf("stutter in status: %s", buf.String()) + } +} diff --git a/libgo/go/net/http/server.go b/libgo/go/net/http/server.go index 924ffd34815..0572b4ae347 100644 --- a/libgo/go/net/http/server.go +++ b/libgo/go/net/http/server.go @@ -31,7 +31,7 @@ import ( // Errors introduced by the HTTP server. var ( ErrWriteAfterFlush = errors.New("Conn.Write called after Flush") - ErrBodyNotAllowed = errors.New("http: response status code does not allow body") + ErrBodyNotAllowed = errors.New("http: request method or response status code does not allow body") ErrHijacked = errors.New("Conn has been hijacked") ErrContentLength = errors.New("Conn.Write wrote more than the declared Content-Length") ) diff --git a/libgo/go/net/http/transfer.go b/libgo/go/net/http/transfer.go index 3c8fe7f5b51..9e9d84172d0 100644 --- a/libgo/go/net/http/transfer.go +++ b/libgo/go/net/http/transfer.go @@ -71,7 +71,9 @@ func newTransferWriter(r interface{}) (t *transferWriter, err error) { } } case *Response: - t.Method = rr.Request.Method + if rr.Request != nil { + t.Method = rr.Request.Method + } t.Body = rr.Body t.BodyCloser = rr.Body t.ContentLength = rr.ContentLength @@ -79,7 +81,7 @@ func newTransferWriter(r interface{}) (t *transferWriter, err error) { t.TransferEncoding = rr.TransferEncoding t.Trailer = rr.Trailer atLeastHTTP11 = rr.ProtoAtLeast(1, 1) - t.ResponseToHEAD = noBodyExpected(rr.Request.Method) + t.ResponseToHEAD = noBodyExpected(t.Method) } // Sanitize Body,ContentLength,TransferEncoding diff --git a/libgo/go/net/http/transport.go b/libgo/go/net/http/transport.go index 024975946e5..6efe191eb0b 100644 --- a/libgo/go/net/http/transport.go +++ b/libgo/go/net/http/transport.go @@ -450,10 +450,14 @@ type connectMethod struct { func (ck *connectMethod) String() string { proxyStr := "" + targetAddr := ck.targetAddr if ck.proxyURL != nil { proxyStr = ck.proxyURL.String() + if ck.targetScheme == "http" { + targetAddr = "" + } } - return strings.Join([]string{proxyStr, ck.targetScheme, ck.targetAddr}, "|") + return strings.Join([]string{proxyStr, ck.targetScheme, targetAddr}, "|") } // addr returns the first hop "host:port" to which we need to TCP connect. diff --git a/libgo/go/net/mail/message.go b/libgo/go/net/mail/message.go index 0917bbedf1b..b610ccf3f04 100644 --- a/libgo/go/net/mail/message.go +++ b/libgo/go/net/mail/message.go @@ -69,11 +69,12 @@ var dateLayouts []string func init() { // Generate layouts based on RFC 5322, section 3.3. - dows := [...]string{"", "Mon, "} // day-of-week - days := [...]string{"2", "02"} // day = 1*2DIGIT - years := [...]string{"2006", "06"} // year = 4*DIGIT / 2*DIGIT - seconds := [...]string{":05", ""} // second - zones := [...]string{"-0700", "MST"} // zone = (("+" / "-") 4DIGIT) / "GMT" / ... + dows := [...]string{"", "Mon, "} // day-of-week + days := [...]string{"2", "02"} // day = 1*2DIGIT + years := [...]string{"2006", "06"} // year = 4*DIGIT / 2*DIGIT + seconds := [...]string{":05", ""} // second + // "-0700 (MST)" is not in RFC 5322, but is common. + zones := [...]string{"-0700", "MST", "-0700 (MST)"} // zone = (("+" / "-") 4DIGIT) / "GMT" / ... for _, dow := range dows { for _, day := range days { diff --git a/libgo/go/net/mail/message_test.go b/libgo/go/net/mail/message_test.go index 671ff2efacb..fd17eb414a7 100644 --- a/libgo/go/net/mail/message_test.go +++ b/libgo/go/net/mail/message_test.go @@ -95,6 +95,11 @@ func TestDateParsing(t *testing.T) { "21 Nov 97 09:55:06 GMT", time.Date(1997, 11, 21, 9, 55, 6, 0, time.FixedZone("GMT", 0)), }, + // Commonly found format not specified by RFC 5322. + { + "Fri, 21 Nov 1997 09:55:06 -0600 (MDT)", + time.Date(1997, 11, 21, 9, 55, 6, 0, time.FixedZone("", -6*60*60)), + }, } for _, test := range tests { hdr := Header{ diff --git a/libgo/go/net/url/url.go b/libgo/go/net/url/url.go index b6e79adc29a..17bf0d3a342 100644 --- a/libgo/go/net/url/url.go +++ b/libgo/go/net/url/url.go @@ -401,11 +401,12 @@ Error: } func parseAuthority(authority string) (user *Userinfo, host string, err error) { - if strings.Index(authority, "@") < 0 { + i := strings.LastIndex(authority, "@") + if i < 0 { host = authority return } - userinfo, host := split(authority, '@', true) + userinfo, host := authority[:i], authority[i+1:] if strings.Index(userinfo, ":") < 0 { if userinfo, err = unescape(userinfo, encodeUserPassword); err != nil { return diff --git a/libgo/go/net/url/url_test.go b/libgo/go/net/url/url_test.go index d8b253142f0..75e8abe4eb3 100644 --- a/libgo/go/net/url/url_test.go +++ b/libgo/go/net/url/url_test.go @@ -188,6 +188,37 @@ var urltests = []URLTest{ }, "http://user:password@google.com", }, + // unescaped @ in username should not confuse host + { + "http://j@ne:password@google.com", + &URL{ + Scheme: "http", + User: UserPassword("j@ne", "password"), + Host: "google.com", + }, + "http://j%40ne:password@google.com", + }, + // unescaped @ in password should not confuse host + { + "http://jane:p@ssword@google.com", + &URL{ + Scheme: "http", + User: UserPassword("jane", "p@ssword"), + Host: "google.com", + }, + "http://jane:p%40ssword@google.com", + }, + { + "http://j@ne:password@google.com/p@th?q=@go", + &URL{ + Scheme: "http", + User: UserPassword("j@ne", "password"), + Host: "google.com", + Path: "/p@th", + RawQuery: "q=@go", + }, + "http://j%40ne:password@google.com/p@th?q=@go", + }, { "http://www.google.com/?q=go+language#foo", &URL{ |