diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-01-12 01:31:45 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-01-12 01:31:45 +0000 |
commit | 9a0e3259f44ad2de9c65f14f756dab01b3598391 (patch) | |
tree | 86a3b8019380d5fad53258c4baba3dd9e1e7c736 /libgo/go/net/http | |
parent | c6135f063335419e4b5df0b4e1caf145882c8a4b (diff) | |
download | gcc-9a0e3259f44ad2de9c65f14f756dab01b3598391.zip gcc-9a0e3259f44ad2de9c65f14f756dab01b3598391.tar.gz gcc-9a0e3259f44ad2de9c65f14f756dab01b3598391.tar.bz2 |
libgo: Update to weekly.2011-12-14.
From-SVN: r183118
Diffstat (limited to 'libgo/go/net/http')
-rw-r--r-- | libgo/go/net/http/doc.go | 4 | ||||
-rw-r--r-- | libgo/go/net/http/serve_test.go | 20 | ||||
-rw-r--r-- | libgo/go/net/http/server.go | 18 | ||||
-rw-r--r-- | libgo/go/net/http/transport.go | 5 | ||||
-rw-r--r-- | libgo/go/net/http/transport_test.go | 2 |
5 files changed, 25 insertions, 24 deletions
diff --git a/libgo/go/net/http/doc.go b/libgo/go/net/http/doc.go index 9c47ac7..2dbcf8d 100644 --- a/libgo/go/net/http/doc.go +++ b/libgo/go/net/http/doc.go @@ -70,8 +70,8 @@ custom Server: s := &http.Server{ Addr: ":8080", Handler: myHandler, - ReadTimeout: 10e9, - WriteTimeout: 10e9, + ReadTimeout: 10 * time.Second, + WriteTimeout: 10 * time.Second, MaxHeaderBytes: 1 << 20, } log.Fatal(s.ListenAndServe()) diff --git a/libgo/go/net/http/serve_test.go b/libgo/go/net/http/serve_test.go index 670b541..c68e661 100644 --- a/libgo/go/net/http/serve_test.go +++ b/libgo/go/net/http/serve_test.go @@ -361,7 +361,7 @@ func TestIdentityResponse(t *testing.T) { // The ReadAll will hang for a failing test, so use a Timer to // fail explicitly. - goTimeout(t, 2e9, func() { + goTimeout(t, 2*time.Second, func() { got, _ := ioutil.ReadAll(conn) expectedSuffix := "\r\n\r\ntoo short" if !strings.HasSuffix(string(got), expectedSuffix) { @@ -395,7 +395,7 @@ func testTcpConnectionCloses(t *testing.T, req string, h Handler) { success := make(chan bool) go func() { select { - case <-time.After(5e9): + case <-time.After(5 * time.Second): t.Fatal("body not closed after 5s") case <-success: } @@ -538,7 +538,7 @@ func TestHeadResponses(t *testing.T) { func TestTLSHandshakeTimeout(t *testing.T) { ts := httptest.NewUnstartedServer(HandlerFunc(func(w ResponseWriter, r *Request) {})) - ts.Config.ReadTimeout = 250e6 + ts.Config.ReadTimeout = 250 * time.Millisecond ts.StartTLS() defer ts.Close() conn, err := net.Dial("tcp", ts.Listener.Addr().String()) @@ -546,7 +546,7 @@ func TestTLSHandshakeTimeout(t *testing.T) { t.Fatalf("Dial: %v", err) } defer conn.Close() - goTimeout(t, 10e9, func() { + goTimeout(t, 10*time.Second, func() { var buf [1]byte n, err := conn.Read(buf[:]) if err == nil || n != 0 { @@ -576,7 +576,7 @@ func TestTLSServer(t *testing.T) { t.Fatalf("Dial: %v", err) } defer idleConn.Close() - goTimeout(t, 10e9, func() { + goTimeout(t, 10*time.Second, func() { if !strings.HasPrefix(ts.URL, "https://") { t.Errorf("expected test TLS server to start with https://, got %q", ts.URL) return @@ -925,7 +925,7 @@ func testHandlerPanic(t *testing.T, withHijack bool) { select { case <-done: return - case <-time.After(5e9): + case <-time.After(5 * time.Second): t.Fatal("expected server handler to log an error") } } @@ -1072,7 +1072,7 @@ func TestClientWriteShutdown(t *testing.T) { }() select { case <-donec: - case <-time.After(10e9): + case <-time.After(10 * time.Second): t.Fatalf("timeout") } } @@ -1103,10 +1103,10 @@ func TestServerBufferedChunking(t *testing.T) { } // goTimeout runs f, failing t if f takes more than ns to complete. -func goTimeout(t *testing.T, ns int64, f func()) { +func goTimeout(t *testing.T, d time.Duration, f func()) { ch := make(chan bool, 2) - timer := time.AfterFunc(ns, func() { - t.Errorf("Timeout expired after %d ns", ns) + timer := time.AfterFunc(d, func() { + t.Errorf("Timeout expired after %v", d) ch <- true }) defer timer.Stop() diff --git a/libgo/go/net/http/server.go b/libgo/go/net/http/server.go index c100e4d..fa90095 100644 --- a/libgo/go/net/http/server.go +++ b/libgo/go/net/http/server.go @@ -261,7 +261,7 @@ func (w *response) Header() Header { } // maxPostHandlerReadBytes is the max number of Request.Body bytes not -// consumed by a handler that the server will read from the a client +// consumed by a handler that the server will read from the client // in order to keep a connection alive. If there are more bytes than // this then the server to be paranoid instead sends a "Connection: // close" response. @@ -952,11 +952,11 @@ func Serve(l net.Listener, handler Handler) error { // A Server defines parameters for running an HTTP server. type Server struct { - Addr string // TCP address to listen on, ":http" if empty - Handler Handler // handler to invoke, http.DefaultServeMux if nil - ReadTimeout int64 // the net.Conn.SetReadTimeout value for new connections - WriteTimeout int64 // the net.Conn.SetWriteTimeout value for new connections - MaxHeaderBytes int // maximum size of request headers, DefaultMaxHeaderBytes if 0 + Addr string // TCP address to listen on, ":http" if empty + Handler Handler // handler to invoke, http.DefaultServeMux if nil + ReadTimeout time.Duration // the net.Conn.SetReadTimeout value for new connections + WriteTimeout time.Duration // the net.Conn.SetWriteTimeout value for new connections + MaxHeaderBytes int // maximum size of request headers, DefaultMaxHeaderBytes if 0 } // ListenAndServe listens on the TCP network address srv.Addr and then @@ -989,10 +989,10 @@ func (srv *Server) Serve(l net.Listener) error { return e } if srv.ReadTimeout != 0 { - rw.SetReadTimeout(srv.ReadTimeout) + rw.SetReadTimeout(srv.ReadTimeout.Nanoseconds()) } if srv.WriteTimeout != 0 { - rw.SetWriteTimeout(srv.WriteTimeout) + rw.SetWriteTimeout(srv.WriteTimeout.Nanoseconds()) } c, err := srv.newConn(rw) if err != nil { @@ -1027,7 +1027,7 @@ func (srv *Server) Serve(l net.Listener) error { // http.HandleFunc("/hello", HelloServer) // err := http.ListenAndServe(":12345", nil) // if err != nil { -// log.Fatal("ListenAndServe: ", err.String()) +// log.Fatal("ListenAndServe: ", err) // } // } func ListenAndServe(addr string, handler Handler) error { diff --git a/libgo/go/net/http/transport.go b/libgo/go/net/http/transport.go index dc70be4..33ad328 100644 --- a/libgo/go/net/http/transport.go +++ b/libgo/go/net/http/transport.go @@ -539,12 +539,13 @@ func (pc *persistConn) readLoop() { resp, err := ReadResponse(pc.br, rc.req) if err == nil { - if rc.addedGzip && resp.Header.Get("Content-Encoding") == "gzip" { + hasBody := rc.req.Method != "HEAD" && resp.ContentLength != 0 + if rc.addedGzip && hasBody && resp.Header.Get("Content-Encoding") == "gzip" { resp.Header.Del("Content-Encoding") resp.Header.Del("Content-Length") resp.ContentLength = -1 gzReader, zerr := gzip.NewReader(resp.Body) - if err != nil { + if zerr != nil { pc.close() err = zerr } else { diff --git a/libgo/go/net/http/transport_test.go b/libgo/go/net/http/transport_test.go index 6f50f6f..ff12fa2 100644 --- a/libgo/go/net/http/transport_test.go +++ b/libgo/go/net/http/transport_test.go @@ -292,7 +292,7 @@ func TestTransportServerClosingUnexpectedly(t *testing.T) { // it on most fast machines, causing the next fetch() call to // succeed quickly. But if we do get errors, fetch() will retry 5 // times with some delays between. - time.Sleep(25e6) + time.Sleep(25 * time.Millisecond) body3 := fetch(3, 5) |