diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-12-03 02:17:34 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-12-03 02:17:34 +0000 |
commit | 2fd401c8f190f1fe43e51a7f726f6ed6119a1f96 (patch) | |
tree | 7f76eff391f37fe6467ff4ffbc0c582c9959ea30 /libgo/go/http | |
parent | 02e9018f1616b23f1276151797216717b3564202 (diff) | |
download | gcc-2fd401c8f190f1fe43e51a7f726f6ed6119a1f96.zip gcc-2fd401c8f190f1fe43e51a7f726f6ed6119a1f96.tar.gz gcc-2fd401c8f190f1fe43e51a7f726f6ed6119a1f96.tar.bz2 |
libgo: Update to weekly.2011-11-02.
From-SVN: r181964
Diffstat (limited to 'libgo/go/http')
33 files changed, 269 insertions, 275 deletions
diff --git a/libgo/go/http/cgi/child.go b/libgo/go/http/cgi/child.go index bf14c04..1618268 100644 --- a/libgo/go/http/cgi/child.go +++ b/libgo/go/http/cgi/child.go @@ -10,6 +10,7 @@ package cgi import ( "bufio" "crypto/tls" + "errors" "fmt" "http" "io" @@ -25,7 +26,7 @@ import ( // environment. This assumes the current program is being run // by a web server in a CGI environment. // The returned Request's Body is populated, if applicable. -func Request() (*http.Request, os.Error) { +func Request() (*http.Request, error) { r, err := RequestFromMap(envMap(os.Environ())) if err != nil { return nil, err @@ -48,18 +49,18 @@ func envMap(env []string) map[string]string { // RequestFromMap creates an http.Request from CGI variables. // The returned Request's Body field is not populated. -func RequestFromMap(params map[string]string) (*http.Request, os.Error) { +func RequestFromMap(params map[string]string) (*http.Request, error) { r := new(http.Request) r.Method = params["REQUEST_METHOD"] if r.Method == "" { - return nil, os.NewError("cgi: no REQUEST_METHOD in environment") + return nil, errors.New("cgi: no REQUEST_METHOD in environment") } r.Proto = params["SERVER_PROTOCOL"] var ok bool r.ProtoMajor, r.ProtoMinor, ok = http.ParseHTTPVersion(r.Proto) if !ok { - return nil, os.NewError("cgi: invalid SERVER_PROTOCOL version") + return nil, errors.New("cgi: invalid SERVER_PROTOCOL version") } r.Close = true @@ -71,7 +72,7 @@ func RequestFromMap(params map[string]string) (*http.Request, os.Error) { if lenstr := params["CONTENT_LENGTH"]; lenstr != "" { clen, err := strconv.Atoi64(lenstr) if err != nil { - return nil, os.NewError("cgi: bad CONTENT_LENGTH in environment: " + lenstr) + return nil, errors.New("cgi: bad CONTENT_LENGTH in environment: " + lenstr) } r.ContentLength = clen } @@ -96,7 +97,7 @@ func RequestFromMap(params map[string]string) (*http.Request, os.Error) { rawurl := "http://" + r.Host + params["REQUEST_URI"] url, err := url.Parse(rawurl) if err != nil { - return nil, os.NewError("cgi: failed to parse host and REQUEST_URI into a URL: " + rawurl) + return nil, errors.New("cgi: failed to parse host and REQUEST_URI into a URL: " + rawurl) } r.URL = url } @@ -106,7 +107,7 @@ func RequestFromMap(params map[string]string) (*http.Request, os.Error) { uriStr := params["REQUEST_URI"] url, err := url.Parse(uriStr) if err != nil { - return nil, os.NewError("cgi: failed to parse REQUEST_URI into a URL: " + uriStr) + return nil, errors.New("cgi: failed to parse REQUEST_URI into a URL: " + uriStr) } r.URL = url } @@ -129,7 +130,7 @@ func RequestFromMap(params map[string]string) (*http.Request, os.Error) { // request, if any. If there's no current CGI environment // an error is returned. The provided handler may be nil to use // http.DefaultServeMux. -func Serve(handler http.Handler) os.Error { +func Serve(handler http.Handler) error { req, err := Request() if err != nil { return err @@ -164,7 +165,7 @@ func (r *response) Header() http.Header { return r.header } -func (r *response) Write(p []byte) (n int, err os.Error) { +func (r *response) Write(p []byte) (n int, err error) { if !r.headerSent { r.WriteHeader(http.StatusOK) } diff --git a/libgo/go/http/cgi/host.go b/libgo/go/http/cgi/host.go index 365a712..8c999c0 100644 --- a/libgo/go/http/cgi/host.go +++ b/libgo/go/http/cgi/host.go @@ -188,7 +188,7 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) { cwd = "." } - internalError := func(err os.Error) { + internalError := func(err error) { rw.WriteHeader(http.StatusInternalServerError) h.printf("CGI error: %v", err) } @@ -227,7 +227,7 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) { h.printf("cgi: long header line from subprocess.") return } - if err == os.EOF { + if err == io.EOF { break } if err != nil { diff --git a/libgo/go/http/cgi/host_test.go b/libgo/go/http/cgi/host_test.go index 6c0f1a0..3227e32 100644 --- a/libgo/go/http/cgi/host_test.go +++ b/libgo/go/http/cgi/host_test.go @@ -45,7 +45,7 @@ readlines: for { line, err := rw.Body.ReadString('\n') switch { - case err == os.EOF: + case err == io.EOF: break readlines case err != nil: t.Fatalf("unexpected error reading from CGI: %v", err) @@ -414,7 +414,7 @@ func TestDirWindows(t *testing.T) { cgifile, _ := filepath.Abs("testdata/test.cgi") var perl string - var err os.Error + var err error perl, err = exec.LookPath("perl") if err != nil { return @@ -456,7 +456,7 @@ func TestEnvOverride(t *testing.T) { cgifile, _ := filepath.Abs("testdata/test.cgi") var perl string - var err os.Error + var err error perl, err = exec.LookPath("perl") if err != nil { return diff --git a/libgo/go/http/chunked.go b/libgo/go/http/chunked.go index eff9ae2..157e1c4 100644 --- a/libgo/go/http/chunked.go +++ b/libgo/go/http/chunked.go @@ -8,7 +8,6 @@ import ( "bufio" "io" "log" - "os" "strconv" ) @@ -37,7 +36,7 @@ type chunkedWriter struct { // Write the contents of data as one chunk to Wire. // NOTE: Note that the corresponding chunk-writing procedure in Conn.Write has // a bug since it does not check for success of io.WriteString -func (cw *chunkedWriter) Write(data []byte) (n int, err os.Error) { +func (cw *chunkedWriter) Write(data []byte) (n int, err error) { // Don't send 0-length data. It looks like EOF for chunked encoding. if len(data) == 0 { @@ -61,7 +60,7 @@ func (cw *chunkedWriter) Write(data []byte) (n int, err os.Error) { return } -func (cw *chunkedWriter) Close() os.Error { +func (cw *chunkedWriter) Close() error { _, err := io.WriteString(cw.Wire, "0\r\n") return err } diff --git a/libgo/go/http/client.go b/libgo/go/http/client.go index e939b96..503cc89 100644 --- a/libgo/go/http/client.go +++ b/libgo/go/http/client.go @@ -11,9 +11,9 @@ package http import ( "encoding/base64" + "errors" "fmt" "io" - "os" "strings" "url" ) @@ -37,7 +37,7 @@ type Client struct { // // If CheckRedirect is nil, the Client uses its default policy, // which is to stop after 10 consecutive requests. - CheckRedirect func(req *Request, via []*Request) os.Error + CheckRedirect func(req *Request, via []*Request) error } // DefaultClient is the default Client and is used by Get, Head, and Post. @@ -62,7 +62,7 @@ type RoundTripper interface { // RoundTrip should not modify the request, except for // consuming the Body. The request's URL and Header fields // are guaranteed to be initialized. - RoundTrip(*Request) (*Response, os.Error) + RoundTrip(*Request) (*Response, error) } // Given a string of the form "host", "host:port", or "[ipv6::address]:port", @@ -88,7 +88,7 @@ type readClose struct { // connection to the server for a subsequent "keep-alive" request. // // Generally Get, Post, or PostForm will be used instead of Do. -func (c *Client) Do(req *Request) (resp *Response, err os.Error) { +func (c *Client) Do(req *Request) (resp *Response, err error) { if req.Method == "GET" || req.Method == "HEAD" { return c.doFollowingRedirects(req) } @@ -96,17 +96,17 @@ func (c *Client) Do(req *Request) (resp *Response, err os.Error) { } // send issues an HTTP request. Caller should close resp.Body when done reading from it. -func send(req *Request, t RoundTripper) (resp *Response, err os.Error) { +func send(req *Request, t RoundTripper) (resp *Response, err error) { if t == nil { t = DefaultTransport if t == nil { - err = os.NewError("http: no Client.Transport or DefaultTransport") + err = errors.New("http: no Client.Transport or DefaultTransport") return } } if req.URL == nil { - return nil, os.NewError("http: nil Request.URL") + return nil, errors.New("http: nil Request.URL") } // Most the callers of send (Get, Post, et al) don't need @@ -144,7 +144,7 @@ func shouldRedirect(statusCode int) bool { // Caller should close r.Body when done reading from it. // // Get is a convenience wrapper around DefaultClient.Get. -func Get(url string) (r *Response, err os.Error) { +func Get(url string) (r *Response, err error) { return DefaultClient.Get(url) } @@ -158,7 +158,7 @@ func Get(url string) (r *Response, err os.Error) { // 307 (Temporary Redirect) // // Caller should close r.Body when done reading from it. -func (c *Client) Get(url string) (r *Response, err os.Error) { +func (c *Client) Get(url string) (r *Response, err error) { req, err := NewRequest("GET", url, nil) if err != nil { return nil, err @@ -166,7 +166,7 @@ func (c *Client) Get(url string) (r *Response, err os.Error) { return c.doFollowingRedirects(req) } -func (c *Client) doFollowingRedirects(ireq *Request) (r *Response, err os.Error) { +func (c *Client) doFollowingRedirects(ireq *Request) (r *Response, err error) { // TODO: if/when we add cookie support, the redirected request shouldn't // necessarily supply the same cookies as the original. var base *url.URL @@ -177,7 +177,7 @@ func (c *Client) doFollowingRedirects(ireq *Request) (r *Response, err os.Error) var via []*Request if ireq.URL == nil { - return nil, os.NewError("http: nil Request.URL") + return nil, errors.New("http: nil Request.URL") } req := ireq @@ -212,7 +212,7 @@ func (c *Client) doFollowingRedirects(ireq *Request) (r *Response, err os.Error) if shouldRedirect(r.StatusCode) { r.Body.Close() if urlStr = r.Header.Get("Location"); urlStr == "" { - err = os.NewError(fmt.Sprintf("%d response missing Location header", r.StatusCode)) + err = errors.New(fmt.Sprintf("%d response missing Location header", r.StatusCode)) break } base = req.URL @@ -227,9 +227,9 @@ func (c *Client) doFollowingRedirects(ireq *Request) (r *Response, err os.Error) return } -func defaultCheckRedirect(req *Request, via []*Request) os.Error { +func defaultCheckRedirect(req *Request, via []*Request) error { if len(via) >= 10 { - return os.NewError("stopped after 10 redirects") + return errors.New("stopped after 10 redirects") } return nil } @@ -239,14 +239,14 @@ func defaultCheckRedirect(req *Request, via []*Request) os.Error { // Caller should close r.Body when done reading from it. // // Post is a wrapper around DefaultClient.Post -func Post(url string, bodyType string, body io.Reader) (r *Response, err os.Error) { +func Post(url string, bodyType string, body io.Reader) (r *Response, err error) { return DefaultClient.Post(url, bodyType, body) } // Post issues a POST to the specified URL. // // Caller should close r.Body when done reading from it. -func (c *Client) Post(url string, bodyType string, body io.Reader) (r *Response, err os.Error) { +func (c *Client) Post(url string, bodyType string, body io.Reader) (r *Response, err error) { req, err := NewRequest("POST", url, body) if err != nil { return nil, err @@ -261,7 +261,7 @@ func (c *Client) Post(url string, bodyType string, body io.Reader) (r *Response, // Caller should close r.Body when done reading from it. // // PostForm is a wrapper around DefaultClient.PostForm -func PostForm(url string, data url.Values) (r *Response, err os.Error) { +func PostForm(url string, data url.Values) (r *Response, err error) { return DefaultClient.PostForm(url, data) } @@ -269,7 +269,7 @@ func PostForm(url string, data url.Values) (r *Response, err os.Error) { // with data's keys and values urlencoded as the request body. // // Caller should close r.Body when done reading from it. -func (c *Client) PostForm(url string, data url.Values) (r *Response, err os.Error) { +func (c *Client) PostForm(url string, data url.Values) (r *Response, err error) { return c.Post(url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode())) } @@ -283,7 +283,7 @@ func (c *Client) PostForm(url string, data url.Values) (r *Response, err os.Erro // 307 (Temporary Redirect) // // Head is a wrapper around DefaultClient.Head -func Head(url string) (r *Response, err os.Error) { +func Head(url string) (r *Response, err error) { return DefaultClient.Head(url) } @@ -295,7 +295,7 @@ func Head(url string) (r *Response, err os.Error) { // 302 (Found) // 303 (See Other) // 307 (Temporary Redirect) -func (c *Client) Head(url string) (r *Response, err os.Error) { +func (c *Client) Head(url string) (r *Response, err error) { req, err := NewRequest("HEAD", url, nil) if err != nil { return nil, err diff --git a/libgo/go/http/client_test.go b/libgo/go/http/client_test.go index 8f61286..fdad2cd 100644 --- a/libgo/go/http/client_test.go +++ b/libgo/go/http/client_test.go @@ -8,13 +8,13 @@ package http_test import ( "crypto/tls" + "errors" "fmt" . "http" "http/httptest" "io" "io/ioutil" "net" - "os" "strconv" "strings" "testing" @@ -60,9 +60,9 @@ type recordingTransport struct { req *Request } -func (t *recordingTransport) RoundTrip(req *Request) (resp *Response, err os.Error) { +func (t *recordingTransport) RoundTrip(req *Request) (resp *Response, err error) { t.req = req - return nil, os.NewError("dummy impl") + return nil, errors.New("dummy impl") } func TestGetRequestFormat(t *testing.T) { @@ -185,9 +185,9 @@ func TestRedirects(t *testing.T) { t.Errorf("with default client Do, expected error %q, got %q", e, g) } - var checkErr os.Error + var checkErr error var lastVia []*Request - c = &Client{CheckRedirect: func(_ *Request, via []*Request) os.Error { + c = &Client{CheckRedirect: func(_ *Request, via []*Request) error { lastVia = via return checkErr }} @@ -203,7 +203,7 @@ func TestRedirects(t *testing.T) { t.Errorf("expected lastVia to have contained %d elements; got %d", e, g) } - checkErr = os.NewError("no redirects allowed") + checkErr = errors.New("no redirects allowed") res, err = c.Get(ts.URL) finalUrl = res.Request.URL.String() if e, g := "Get /?n=1: no redirects allowed", fmt.Sprintf("%v", err); e != g { @@ -244,7 +244,7 @@ func TestStreamingGet(t *testing.T) { } close(say) _, err = io.ReadFull(res.Body, buf[0:1]) - if err != os.EOF { + if err != io.EOF { t.Fatalf("at end expected EOF, got %v", err) } } @@ -254,7 +254,7 @@ type writeCountingConn struct { count *int } -func (c *writeCountingConn) Write(p []byte) (int, os.Error) { +func (c *writeCountingConn) Write(p []byte) (int, error) { *c.count++ return c.Conn.Write(p) } @@ -267,7 +267,7 @@ func TestClientWrites(t *testing.T) { defer ts.Close() writes := 0 - dialer := func(netz string, addr string) (net.Conn, os.Error) { + dialer := func(netz string, addr string) (net.Conn, error) { c, err := net.Dial(netz, addr) if err == nil { c = &writeCountingConn{c, &writes} diff --git a/libgo/go/http/cookie_test.go b/libgo/go/http/cookie_test.go index 5de6aab..9a537f9 100644 --- a/libgo/go/http/cookie_test.go +++ b/libgo/go/http/cookie_test.go @@ -7,7 +7,6 @@ package http import ( "fmt" "json" - "os" "reflect" "testing" "time" @@ -50,7 +49,7 @@ func (ho headerOnlyResponseWriter) Header() Header { return Header(ho) } -func (ho headerOnlyResponseWriter) Write([]byte) (int, os.Error) { +func (ho headerOnlyResponseWriter) Write([]byte) (int, error) { panic("NOIMPL") } diff --git a/libgo/go/http/dump.go b/libgo/go/http/dump.go index f78df57..b85feea 100644 --- a/libgo/go/http/dump.go +++ b/libgo/go/http/dump.go @@ -8,14 +8,13 @@ import ( "bytes" "io" "io/ioutil" - "os" ) // One of the copies, say from b to r2, could be avoided by using a more // elaborate trick where the other copy is made during Request/Response.Write. // This would complicate things too much, given that these functions are for // debugging only. -func drainBody(b io.ReadCloser) (r1, r2 io.ReadCloser, err os.Error) { +func drainBody(b io.ReadCloser) (r1, r2 io.ReadCloser, err error) { var buf bytes.Buffer if _, err = buf.ReadFrom(b); err != nil { return nil, nil, err @@ -33,7 +32,7 @@ func drainBody(b io.ReadCloser) (r1, r2 io.ReadCloser, err os.Error) { // changes req.Body to refer to the in-memory copy. // The documentation for Request.Write details which fields // of req are used. -func DumpRequest(req *Request, body bool) (dump []byte, err os.Error) { +func DumpRequest(req *Request, body bool) (dump []byte, err error) { var b bytes.Buffer save := req.Body if !body || req.Body == nil { @@ -54,7 +53,7 @@ func DumpRequest(req *Request, body bool) (dump []byte, err os.Error) { } // DumpResponse is like DumpRequest but dumps a response. -func DumpResponse(resp *Response, body bool) (dump []byte, err os.Error) { +func DumpResponse(resp *Response, body bool) (dump []byte, err error) { var b bytes.Buffer save := resp.Body savecl := resp.ContentLength diff --git a/libgo/go/http/fcgi/child.go b/libgo/go/http/fcgi/child.go index 61dd3fb..f6591e0 100644 --- a/libgo/go/http/fcgi/child.go +++ b/libgo/go/http/fcgi/child.go @@ -80,7 +80,7 @@ func (r *response) Header() http.Header { return r.header } -func (r *response) Write(data []byte) (int, os.Error) { +func (r *response) Write(data []byte) (int, error) { if !r.wroteHeader { r.WriteHeader(http.StatusOK) } @@ -117,7 +117,7 @@ func (r *response) Flush() { r.w.Flush() } -func (r *response) Close() os.Error { +func (r *response) Close() error { r.Flush() return r.w.Close() } @@ -214,7 +214,7 @@ func (c *child) serveRequest(req *request, body io.ReadCloser) { if err != nil { // there was an error reading the request r.WriteHeader(http.StatusInternalServerError) - c.conn.writeRecord(typeStderr, req.reqId, []byte(err.String())) + c.conn.writeRecord(typeStderr, req.reqId, []byte(err.Error())) } else { httpReq.Body = body c.handler.ServeHTTP(r, httpReq) @@ -234,9 +234,9 @@ func (c *child) serveRequest(req *request, body io.ReadCloser) { // to reply to them. // If l is nil, Serve accepts connections on stdin. // If handler is nil, http.DefaultServeMux is used. -func Serve(l net.Listener, handler http.Handler) os.Error { +func Serve(l net.Listener, handler http.Handler) error { if l == nil { - var err os.Error + var err error l, err = net.FileListener(os.Stdin) if err != nil { return err diff --git a/libgo/go/http/fcgi/fcgi.go b/libgo/go/http/fcgi/fcgi.go index 8e2e1cd..70cf781 100644 --- a/libgo/go/http/fcgi/fcgi.go +++ b/libgo/go/http/fcgi/fcgi.go @@ -14,8 +14,8 @@ import ( "bufio" "bytes" "encoding/binary" + "errors" "io" - "os" "sync" ) @@ -72,9 +72,9 @@ type beginRequest struct { reserved [5]uint8 } -func (br *beginRequest) read(content []byte) os.Error { +func (br *beginRequest) read(content []byte) error { if len(content) != 8 { - return os.NewError("fcgi: invalid begin request record") + return errors.New("fcgi: invalid begin request record") } br.role = binary.BigEndian.Uint16(content) br.flags = content[2] @@ -107,7 +107,7 @@ func newConn(rwc io.ReadWriteCloser) *conn { return &conn{rwc: rwc} } -func (c *conn) Close() os.Error { +func (c *conn) Close() error { c.mutex.Lock() defer c.mutex.Unlock() return c.rwc.Close() @@ -118,12 +118,12 @@ type record struct { buf [maxWrite + maxPad]byte } -func (rec *record) read(r io.Reader) (err os.Error) { +func (rec *record) read(r io.Reader) (err error) { if err = binary.Read(r, binary.BigEndian, &rec.h); err != nil { return err } if rec.h.Version != 1 { - return os.NewError("fcgi: invalid header version") + return errors.New("fcgi: invalid header version") } n := int(rec.h.ContentLength) + int(rec.h.PaddingLength) if _, err = io.ReadFull(r, rec.buf[:n]); err != nil { @@ -137,7 +137,7 @@ func (r *record) content() []byte { } // writeRecord writes and sends a single record. -func (c *conn) writeRecord(recType uint8, reqId uint16, b []byte) os.Error { +func (c *conn) writeRecord(recType uint8, reqId uint16, b []byte) error { c.mutex.Lock() defer c.mutex.Unlock() c.buf.Reset() @@ -155,19 +155,19 @@ func (c *conn) writeRecord(recType uint8, reqId uint16, b []byte) os.Error { return err } -func (c *conn) writeBeginRequest(reqId uint16, role uint16, flags uint8) os.Error { +func (c *conn) writeBeginRequest(reqId uint16, role uint16, flags uint8) error { b := [8]byte{byte(role >> 8), byte(role), flags} return c.writeRecord(typeBeginRequest, reqId, b[:]) } -func (c *conn) writeEndRequest(reqId uint16, appStatus int, protocolStatus uint8) os.Error { +func (c *conn) writeEndRequest(reqId uint16, appStatus int, protocolStatus uint8) error { b := make([]byte, 8) binary.BigEndian.PutUint32(b, uint32(appStatus)) b[4] = protocolStatus return c.writeRecord(typeEndRequest, reqId, b) } -func (c *conn) writePairs(recType uint8, reqId uint16, pairs map[string]string) os.Error { +func (c *conn) writePairs(recType uint8, reqId uint16, pairs map[string]string) error { w := newWriter(c, recType, reqId) b := make([]byte, 8) for k, v := range pairs { @@ -227,7 +227,7 @@ type bufWriter struct { *bufio.Writer } -func (w *bufWriter) Close() os.Error { +func (w *bufWriter) Close() error { if err := w.Writer.Flush(); err != nil { w.closer.Close() return err @@ -249,7 +249,7 @@ type streamWriter struct { reqId uint16 } -func (w *streamWriter) Write(p []byte) (int, os.Error) { +func (w *streamWriter) Write(p []byte) (int, error) { nn := 0 for len(p) > 0 { n := len(p) @@ -265,7 +265,7 @@ func (w *streamWriter) Write(p []byte) (int, os.Error) { return nn, nil } -func (w *streamWriter) Close() os.Error { +func (w *streamWriter) Close() error { // send empty record to close the stream return w.c.writeRecord(w.recType, w.reqId, nil) } diff --git a/libgo/go/http/fcgi/fcgi_test.go b/libgo/go/http/fcgi/fcgi_test.go index 5c8e46b..e42f8ef 100644 --- a/libgo/go/http/fcgi/fcgi_test.go +++ b/libgo/go/http/fcgi/fcgi_test.go @@ -7,7 +7,6 @@ package fcgi import ( "bytes" "io" - "os" "testing" ) @@ -69,7 +68,7 @@ type nilCloser struct { io.ReadWriter } -func (c *nilCloser) Close() os.Error { return nil } +func (c *nilCloser) Close() error { return nil } func TestStreams(t *testing.T) { var rec record diff --git a/libgo/go/http/filetransport.go b/libgo/go/http/filetransport.go index 78f3aa2..821787e 100644 --- a/libgo/go/http/filetransport.go +++ b/libgo/go/http/filetransport.go @@ -7,7 +7,6 @@ package http import ( "fmt" "io" - "os" ) // fileTransport implements RoundTripper for the 'file' protocol. @@ -32,7 +31,7 @@ func NewFileTransport(fs FileSystem) RoundTripper { return fileTransport{fileHandler{fs}} } -func (t fileTransport) RoundTrip(req *Request) (resp *Response, err os.Error) { +func (t fileTransport) RoundTrip(req *Request) (resp *Response, err error) { // We start ServeHTTP in a goroutine, which may take a long // time if the file is large. The newPopulateResponseWriter // call returns a channel which either ServeHTTP or finish() @@ -112,7 +111,7 @@ func (pr *populateResponse) WriteHeader(code int) { pr.res.Status = fmt.Sprintf("%d %s", code, StatusText(code)) } -func (pr *populateResponse) Write(p []byte) (n int, err os.Error) { +func (pr *populateResponse) Write(p []byte) (n int, err error) { if !pr.wroteHeader { pr.WriteHeader(StatusOK) } diff --git a/libgo/go/http/filetransport_test.go b/libgo/go/http/filetransport_test.go index 2634243..aaee73e 100644 --- a/libgo/go/http/filetransport_test.go +++ b/libgo/go/http/filetransport_test.go @@ -8,12 +8,11 @@ import ( "http" "io/ioutil" "path/filepath" - "os" "testing" ) -func checker(t *testing.T) func(string, os.Error) { - return func(call string, err os.Error) { +func checker(t *testing.T) func(string, error) { + return func(call string, err error) { if err == nil { return } diff --git a/libgo/go/http/fs.go b/libgo/go/http/fs.go index 6d71665..eb0c67d 100644 --- a/libgo/go/http/fs.go +++ b/libgo/go/http/fs.go @@ -7,6 +7,7 @@ package http import ( + "errors" "fmt" "io" "mime" @@ -23,9 +24,9 @@ import ( // system restricted to a specific directory tree. type Dir string -func (d Dir) Open(name string) (File, os.Error) { +func (d Dir) Open(name string) (File, error) { if filepath.Separator != '/' && strings.IndexRune(name, filepath.Separator) >= 0 { - return nil, os.NewError("http: invalid character in file path") + return nil, errors.New("http: invalid character in file path") } f, err := os.Open(filepath.Join(string(d), filepath.FromSlash(path.Clean("/"+name)))) if err != nil { @@ -38,17 +39,17 @@ func (d Dir) Open(name string) (File, os.Error) { // The elements in a file path are separated by slash ('/', U+002F) // characters, regardless of host operating system convention. type FileSystem interface { - Open(name string) (File, os.Error) + Open(name string) (File, error) } // A File is returned by a FileSystem's Open method and can be // served by the FileServer implementation. type File interface { - Close() os.Error - Stat() (*os.FileInfo, os.Error) - Readdir(count int) ([]os.FileInfo, os.Error) - Read([]byte) (int, os.Error) - Seek(offset int64, whence int) (int64, os.Error) + Close() error + Stat() (*os.FileInfo, error) + Readdir(count int) ([]os.FileInfo, error) + Read([]byte) (int, error) + Seek(offset int64, whence int) (int64, error) } // Heuristic: b is text if it is valid UTF-8 and doesn't @@ -194,16 +195,16 @@ func serveFile(w ResponseWriter, r *Request, fs FileSystem, name string, redirec // TODO(adg): handle multiple ranges ranges, err := parseRange(r.Header.Get("Range"), size) if err == nil && len(ranges) > 1 { - err = os.NewError("multiple ranges not supported") + err = errors.New("multiple ranges not supported") } if err != nil { - Error(w, err.String(), StatusRequestedRangeNotSatisfiable) + Error(w, err.Error(), StatusRequestedRangeNotSatisfiable) return } if len(ranges) == 1 { ra := ranges[0] if _, err := f.Seek(ra.start, os.SEEK_SET); err != nil { - Error(w, err.String(), StatusRequestedRangeNotSatisfiable) + Error(w, err.Error(), StatusRequestedRangeNotSatisfiable) return } size = ra.length @@ -269,19 +270,19 @@ type httpRange struct { } // parseRange parses a Range header string as per RFC 2616. -func parseRange(s string, size int64) ([]httpRange, os.Error) { +func parseRange(s string, size int64) ([]httpRange, error) { if s == "" { return nil, nil // header not present } const b = "bytes=" if !strings.HasPrefix(s, b) { - return nil, os.NewError("invalid range") + return nil, errors.New("invalid range") } var ranges []httpRange for _, ra := range strings.Split(s[len(b):], ",") { i := strings.Index(ra, "-") if i < 0 { - return nil, os.NewError("invalid range") + return nil, errors.New("invalid range") } start, end := ra[:i], ra[i+1:] var r httpRange @@ -290,7 +291,7 @@ func parseRange(s string, size int64) ([]httpRange, os.Error) { // range start relative to the end of the file. i, err := strconv.Atoi64(end) if err != nil { - return nil, os.NewError("invalid range") + return nil, errors.New("invalid range") } if i > size { i = size @@ -300,7 +301,7 @@ func parseRange(s string, size int64) ([]httpRange, os.Error) { } else { i, err := strconv.Atoi64(start) if err != nil || i > size || i < 0 { - return nil, os.NewError("invalid range") + return nil, errors.New("invalid range") } r.start = i if end == "" { @@ -309,7 +310,7 @@ func parseRange(s string, size int64) ([]httpRange, os.Error) { } else { i, err := strconv.Atoi64(end) if err != nil || r.start > i { - return nil, os.NewError("invalid range") + return nil, errors.New("invalid range") } if i >= size { i = size - 1 diff --git a/libgo/go/http/fs_test.go b/libgo/go/http/fs_test.go index bb6d015..76312e8 100644 --- a/libgo/go/http/fs_test.go +++ b/libgo/go/http/fs_test.go @@ -40,7 +40,7 @@ func TestServeFile(t *testing.T) { })) defer ts.Close() - var err os.Error + var err error file, err := ioutil.ReadFile(testFile) if err != nil { @@ -113,16 +113,16 @@ func TestFSRedirect(t *testing.T) { } type testFileSystem struct { - open func(name string) (File, os.Error) + open func(name string) (File, error) } -func (fs *testFileSystem) Open(name string) (File, os.Error) { +func (fs *testFileSystem) Open(name string) (File, error) { return fs.open(name) } func TestFileServerCleans(t *testing.T) { ch := make(chan string, 1) - fs := FileServer(&testFileSystem{func(name string) (File, os.Error) { + fs := FileServer(&testFileSystem{func(name string) (File, error) { ch <- name return nil, os.ENOENT }}) diff --git a/libgo/go/http/header.go b/libgo/go/http/header.go index aaaa92a..6be6016 100644 --- a/libgo/go/http/header.go +++ b/libgo/go/http/header.go @@ -8,7 +8,6 @@ import ( "fmt" "io" "net/textproto" - "os" "sort" "strings" ) @@ -43,7 +42,7 @@ func (h Header) Del(key string) { } // Write writes a header in wire format. -func (h Header) Write(w io.Writer) os.Error { +func (h Header) Write(w io.Writer) error { return h.WriteSubset(w, nil) } @@ -51,7 +50,7 @@ var headerNewlineToSpace = strings.NewReplacer("\n", " ", "\r", " ") // WriteSubset writes a header in wire format. // If exclude is not nil, keys where exclude[key] == true are not written. -func (h Header) WriteSubset(w io.Writer, exclude map[string]bool) os.Error { +func (h Header) WriteSubset(w io.Writer, exclude map[string]bool) error { keys := make([]string, 0, len(h)) for k := range h { if exclude == nil || !exclude[k] { diff --git a/libgo/go/http/httptest/recorder.go b/libgo/go/http/httptest/recorder.go index f2fedef..f69279f 100644 --- a/libgo/go/http/httptest/recorder.go +++ b/libgo/go/http/httptest/recorder.go @@ -8,7 +8,6 @@ package httptest import ( "bytes" "http" - "os" ) // ResponseRecorder is an implementation of http.ResponseWriter that @@ -38,7 +37,7 @@ func (rw *ResponseRecorder) Header() http.Header { } // Write always succeeds and writes to rw.Body, if not nil. -func (rw *ResponseRecorder) Write(buf []byte) (int, os.Error) { +func (rw *ResponseRecorder) Write(buf []byte) (int, error) { if rw.Body != nil { rw.Body.Write(buf) } diff --git a/libgo/go/http/httptest/server.go b/libgo/go/http/httptest/server.go index 43a48eb..ea719cf 100644 --- a/libgo/go/http/httptest/server.go +++ b/libgo/go/http/httptest/server.go @@ -36,7 +36,7 @@ type historyListener struct { history []net.Conn } -func (hs *historyListener) Accept() (c net.Conn, err os.Error) { +func (hs *historyListener) Accept() (c net.Conn, err error) { c, err = hs.Listener.Accept() if err == nil { hs.history = append(hs.history, c) diff --git a/libgo/go/http/persist.go b/libgo/go/http/persist.go index f73e6c6..7d84e96 100644 --- a/libgo/go/http/persist.go +++ b/libgo/go/http/persist.go @@ -6,6 +6,7 @@ package http import ( "bufio" + "errors" "io" "net" "net/textproto" @@ -31,7 +32,7 @@ type ServerConn struct { lk sync.Mutex // read-write protects the following fields c net.Conn r *bufio.Reader - re, we os.Error // read/write errors + re, we error // read/write errors lastbody io.ReadCloser nread, nwritten int pipereq map[*Request]uint @@ -63,7 +64,7 @@ func (sc *ServerConn) Hijack() (c net.Conn, r *bufio.Reader) { } // Close calls Hijack and then also closes the underlying connection -func (sc *ServerConn) Close() os.Error { +func (sc *ServerConn) Close() error { c, _ := sc.Hijack() if c != nil { return c.Close() @@ -75,7 +76,7 @@ func (sc *ServerConn) Close() os.Error { // it is gracefully determined that there are no more requests (e.g. after the // first request on an HTTP/1.0 connection, or after a Connection:close on a // HTTP/1.1 connection). -func (sc *ServerConn) Read() (req *Request, err os.Error) { +func (sc *ServerConn) Read() (req *Request, err error) { // Ensure ordered execution of Reads and Writes id := sc.pipe.Next() @@ -160,7 +161,7 @@ func (sc *ServerConn) Pending() int { // Write writes resp in response to req. To close the connection gracefully, set the // Response.Close field to true. Write should be considered operational until // it returns an error, regardless of any errors returned on the Read side. -func (sc *ServerConn) Write(req *Request, resp *Response) os.Error { +func (sc *ServerConn) Write(req *Request, resp *Response) error { // Retrieve the pipeline ID of this request/response pair sc.lk.Lock() @@ -188,7 +189,7 @@ func (sc *ServerConn) Write(req *Request, resp *Response) os.Error { c := sc.c if sc.nread <= sc.nwritten { defer sc.lk.Unlock() - return os.NewError("persist server pipe count") + return errors.New("persist server pipe count") } if resp.Close { // After signaling a keep-alive close, any pipelined unread @@ -221,13 +222,13 @@ type ClientConn struct { lk sync.Mutex // read-write protects the following fields c net.Conn r *bufio.Reader - re, we os.Error // read/write errors + re, we error // read/write errors lastbody io.ReadCloser nread, nwritten int pipereq map[*Request]uint pipe textproto.Pipeline - writeReq func(*Request, io.Writer) os.Error + writeReq func(*Request, io.Writer) error } // NewClientConn returns a new ClientConn reading and writing c. If r is not @@ -267,7 +268,7 @@ func (cc *ClientConn) Hijack() (c net.Conn, r *bufio.Reader) { } // Close calls Hijack and then also closes the underlying connection -func (cc *ClientConn) Close() os.Error { +func (cc *ClientConn) Close() error { c, _ := cc.Hijack() if c != nil { return c.Close() @@ -280,7 +281,7 @@ func (cc *ClientConn) Close() os.Error { // keepalive connection is logically closed after this request and the opposing // server is informed. An ErrUnexpectedEOF indicates the remote closed the // underlying TCP connection, which is usually considered as graceful close. -func (cc *ClientConn) Write(req *Request) (err os.Error) { +func (cc *ClientConn) Write(req *Request) (err error) { // Ensure ordered execution of Writes id := cc.pipe.Next() @@ -343,13 +344,13 @@ func (cc *ClientConn) Pending() int { // returned together with an ErrPersistEOF, which means that the remote // requested that this be the last request serviced. Read can be called // concurrently with Write, but not with another Read. -func (cc *ClientConn) Read(req *Request) (*Response, os.Error) { +func (cc *ClientConn) Read(req *Request) (*Response, error) { return cc.readUsing(req, ReadResponse) } // readUsing is the implementation of Read with a replaceable // ReadResponse-like function, used by the Transport. -func (cc *ClientConn) readUsing(req *Request, readRes func(*bufio.Reader, *Request) (*Response, os.Error)) (resp *Response, err os.Error) { +func (cc *ClientConn) readUsing(req *Request, readRes func(*bufio.Reader, *Request) (*Response, error)) (resp *Response, err error) { // Retrieve the pipeline ID of this request/response pair cc.lk.Lock() id, ok := cc.pipereq[req] @@ -411,7 +412,7 @@ func (cc *ClientConn) readUsing(req *Request, readRes func(*bufio.Reader, *Reque } // Do is convenience method that writes a request and reads a response. -func (cc *ClientConn) Do(req *Request) (resp *Response, err os.Error) { +func (cc *ClientConn) Do(req *Request) (resp *Response, err error) { err = cc.Write(req) if err != nil { return diff --git a/libgo/go/http/pprof/pprof.go b/libgo/go/http/pprof/pprof.go index 917c7f8..a118a25 100644 --- a/libgo/go/http/pprof/pprof.go +++ b/libgo/go/http/pprof/pprof.go @@ -29,6 +29,7 @@ import ( "bytes" "fmt" "http" + "io" "os" "runtime" "runtime/pprof" @@ -121,7 +122,7 @@ func Symbol(w http.ResponseWriter, r *http.Request) { // Wait until here to check for err; the last // symbol will have an err because it doesn't end in +. if err != nil { - if err != os.EOF { + if err != io.EOF { fmt.Fprintf(&buf, "reading request: %v\n", err) } break diff --git a/libgo/go/http/readrequest_test.go b/libgo/go/http/readrequest_test.go index 6d9042a..d62133d 100644 --- a/libgo/go/http/readrequest_test.go +++ b/libgo/go/http/readrequest_test.go @@ -159,8 +159,8 @@ func TestReadRequest(t *testing.T) { braw.WriteString(tt.Raw) req, err := ReadRequest(bufio.NewReader(&braw)) if err != nil { - if err.String() != tt.Error { - t.Errorf("#%d: error %q, want error %q", i, err.String(), tt.Error) + if err.Error() != tt.Error { + t.Errorf("#%d: error %q, want error %q", i, err.Error(), tt.Error) } continue } diff --git a/libgo/go/http/request.go b/libgo/go/http/request.go index 78e07ec..d9a04ef 100644 --- a/libgo/go/http/request.go +++ b/libgo/go/http/request.go @@ -11,13 +11,13 @@ import ( "bytes" "crypto/tls" "encoding/base64" + "errors" "fmt" "io" "io/ioutil" "mime" "mime/multipart" "net/textproto" - "os" "strconv" "strings" "url" @@ -33,14 +33,14 @@ const ( // ErrMissingFile is returned by FormFile when the provided file field name // is either not present in the request or not a file field. -var ErrMissingFile = os.NewError("http: no such file") +var ErrMissingFile = errors.New("http: no such file") // HTTP request parsing errors. type ProtocolError struct { ErrorString string } -func (err *ProtocolError) String() string { return err.ErrorString } +func (err *ProtocolError) Error() string { return err.ErrorString } var ( ErrLineTooLong = &ProtocolError{"header line too long"} @@ -58,7 +58,7 @@ type badStringError struct { str string } -func (e *badStringError) String() string { return fmt.Sprintf("%s %q", e.what, e.str) } +func (e *badStringError) Error() string { return fmt.Sprintf("%s %q", e.what, e.str) } // Headers that Request.Write handles itself and should be skipped. var reqWriteExcludeHeader = map[string]bool{ @@ -174,11 +174,11 @@ func (r *Request) Cookies() []*Cookie { return readCookies(r.Header, "") } -var ErrNoCookie = os.NewError("http: named cookied not present") +var ErrNoCookie = errors.New("http: named cookied not present") // Cookie returns the named cookie provided in the request or // ErrNoCookie if not found. -func (r *Request) Cookie(name string) (*Cookie, os.Error) { +func (r *Request) Cookie(name string) (*Cookie, error) { for _, c := range readCookies(r.Header, name) { return c, nil } @@ -222,18 +222,18 @@ var multipartByReader = &multipart.Form{ // multipart/form-data POST request, else returns nil and an error. // Use this function instead of ParseMultipartForm to // process the request body as a stream. -func (r *Request) MultipartReader() (*multipart.Reader, os.Error) { +func (r *Request) MultipartReader() (*multipart.Reader, error) { if r.MultipartForm == multipartByReader { - return nil, os.NewError("http: MultipartReader called twice") + return nil, errors.New("http: MultipartReader called twice") } if r.MultipartForm != nil { - return nil, os.NewError("http: multipart handled by ParseMultipartForm") + return nil, errors.New("http: multipart handled by ParseMultipartForm") } r.MultipartForm = multipartByReader return r.multipartReader() } -func (r *Request) multipartReader() (*multipart.Reader, os.Error) { +func (r *Request) multipartReader() (*multipart.Reader, error) { v := r.Header.Get("Content-Type") if v == "" { return nil, ErrNotMultipart @@ -272,7 +272,7 @@ const defaultUserAgent = "Go http package" // If Body is present, Content-Length is <= 0 and TransferEncoding // hasn't been set to "identity", Write adds "Transfer-Encoding: // chunked" to the header. Body is closed after it is sent. -func (req *Request) Write(w io.Writer) os.Error { +func (req *Request) Write(w io.Writer) error { return req.write(w, false, nil) } @@ -282,11 +282,11 @@ func (req *Request) Write(w io.Writer) os.Error { // section 5.1.2 of RFC 2616, including the scheme and host. In // either case, WriteProxy also writes a Host header, using either // req.Host or req.URL.Host. -func (req *Request) WriteProxy(w io.Writer) os.Error { +func (req *Request) WriteProxy(w io.Writer) error { return req.write(w, true, nil) } -func (req *Request) dumpWrite(w io.Writer) os.Error { +func (req *Request) dumpWrite(w io.Writer) error { // TODO(bradfitz): RawPath here? urlStr := valueOrDefault(req.URL.EncodedPath(), "/") if req.URL.RawQuery != "" { @@ -332,11 +332,11 @@ func (req *Request) dumpWrite(w io.Writer) os.Error { } // extraHeaders may be nil -func (req *Request) write(w io.Writer, usingProxy bool, extraHeaders Header) os.Error { +func (req *Request) write(w io.Writer, usingProxy bool, extraHeaders Header) error { host := req.Host if host == "" { if req.URL == nil { - return os.NewError("http: Request.Write on Request with no Host or URL set") + return errors.New("http: Request.Write on Request with no Host or URL set") } host = req.URL.Host } @@ -415,11 +415,11 @@ func (req *Request) write(w io.Writer, usingProxy bool, extraHeaders Header) os. // Give up if the line exceeds maxLineLength. // The returned bytes are a pointer into storage in // the bufio, so they are only valid until the next bufio read. -func readLineBytes(b *bufio.Reader) (p []byte, err os.Error) { +func readLineBytes(b *bufio.Reader) (p []byte, err error) { if p, err = b.ReadSlice('\n'); err != nil { // We always know when EOF is coming. // If the caller asked for a line, there should be a line. - if err == os.EOF { + if err == io.EOF { err = io.ErrUnexpectedEOF } else if err == bufio.ErrBufferFull { err = ErrLineTooLong @@ -441,7 +441,7 @@ func readLineBytes(b *bufio.Reader) (p []byte, err os.Error) { } // readLineBytes, but convert the bytes into a string. -func readLine(b *bufio.Reader) (s string, err os.Error) { +func readLine(b *bufio.Reader) (s string, err error) { p, e := readLineBytes(b) if e != nil { return "", e @@ -487,7 +487,7 @@ func ParseHTTPVersion(vers string) (major, minor int, ok bool) { type chunkedReader struct { r *bufio.Reader n uint64 // unread bytes in chunk - err os.Error + err error } func (cr *chunkedReader) beginChunk() { @@ -512,11 +512,11 @@ func (cr *chunkedReader) beginChunk() { break } } - cr.err = os.EOF + cr.err = io.EOF } } -func (cr *chunkedReader) Read(b []uint8) (n int, err os.Error) { +func (cr *chunkedReader) Read(b []uint8) (n int, err error) { if cr.err != nil { return 0, cr.err } @@ -536,7 +536,7 @@ func (cr *chunkedReader) Read(b []uint8) (n int, err os.Error) { b := make([]byte, 2) if _, cr.err = io.ReadFull(cr.r, b); cr.err == nil { if b[0] != '\r' || b[1] != '\n' { - cr.err = os.NewError("malformed chunked encoding") + cr.err = errors.New("malformed chunked encoding") } } } @@ -544,7 +544,7 @@ func (cr *chunkedReader) Read(b []uint8) (n int, err os.Error) { } // NewRequest returns a new Request given a method, URL, and optional body. -func NewRequest(method, urlStr string, body io.Reader) (*Request, os.Error) { +func NewRequest(method, urlStr string, body io.Reader) (*Request, error) { u, err := url.Parse(urlStr) if err != nil { return nil, err @@ -586,7 +586,7 @@ func (r *Request) SetBasicAuth(username, password string) { } // ReadRequest reads and parses a request from b. -func ReadRequest(b *bufio.Reader) (req *Request, err os.Error) { +func ReadRequest(b *bufio.Reader) (req *Request, err error) { tp := textproto.NewReader(b) req = new(Request) @@ -594,7 +594,7 @@ func ReadRequest(b *bufio.Reader) (req *Request, err os.Error) { // First line: GET /index.html HTTP/1.0 var s string if s, err = tp.ReadLine(); err != nil { - if err == os.EOF { + if err == io.EOF { err = io.ErrUnexpectedEOF } return nil, err @@ -690,7 +690,7 @@ type maxBytesReader struct { stopped bool } -func (l *maxBytesReader) Read(p []byte) (n int, err os.Error) { +func (l *maxBytesReader) Read(p []byte) (n int, err error) { if l.n <= 0 { if !l.stopped { l.stopped = true @@ -698,7 +698,7 @@ func (l *maxBytesReader) Read(p []byte) (n int, err os.Error) { res.requestTooLarge() } } - return 0, os.NewError("http: request body too large") + return 0, errors.New("http: request body too large") } if int64(len(p)) > l.n { p = p[:l.n] @@ -708,7 +708,7 @@ func (l *maxBytesReader) Read(p []byte) (n int, err os.Error) { return } -func (l *maxBytesReader) Close() os.Error { +func (l *maxBytesReader) Close() error { return l.r.Close() } @@ -720,7 +720,7 @@ func (l *maxBytesReader) Close() os.Error { // // ParseMultipartForm calls ParseForm automatically. // It is idempotent. -func (r *Request) ParseForm() (err os.Error) { +func (r *Request) ParseForm() (err error) { if r.Form != nil { return } @@ -729,7 +729,7 @@ func (r *Request) ParseForm() (err os.Error) { } if r.Method == "POST" || r.Method == "PUT" { if r.Body == nil { - return os.NewError("missing form body") + return errors.New("missing form body") } ct := r.Header.Get("Content-Type") ct, _, err := mime.ParseMediaType(ct) @@ -749,7 +749,7 @@ func (r *Request) ParseForm() (err os.Error) { break } if int64(len(b)) > maxFormSize { - return os.NewError("http: POST too large") + return errors.New("http: POST too large") } var newValues url.Values newValues, e = url.ParseQuery(string(b)) @@ -785,9 +785,9 @@ func (r *Request) ParseForm() (err os.Error) { // disk in temporary files. // ParseMultipartForm calls ParseForm if necessary. // After one call to ParseMultipartForm, subsequent calls have no effect. -func (r *Request) ParseMultipartForm(maxMemory int64) os.Error { +func (r *Request) ParseMultipartForm(maxMemory int64) error { if r.MultipartForm == multipartByReader { - return os.NewError("http: multipart handled by MultipartReader") + return errors.New("http: multipart handled by MultipartReader") } if r.Form == nil { err := r.ParseForm() @@ -832,9 +832,9 @@ func (r *Request) FormValue(key string) string { // FormFile returns the first file for the provided form key. // FormFile calls ParseMultipartForm and ParseForm if necessary. -func (r *Request) FormFile(key string) (multipart.File, *multipart.FileHeader, os.Error) { +func (r *Request) FormFile(key string) (multipart.File, *multipart.FileHeader, error) { if r.MultipartForm == multipartByReader { - return nil, nil, os.NewError("http: multipart handled by MultipartReader") + return nil, nil, errors.New("http: multipart handled by MultipartReader") } if r.MultipartForm == nil { err := r.ParseMultipartForm(defaultMaxMemory) diff --git a/libgo/go/http/request_test.go b/libgo/go/http/request_test.go index 175d6f1..9be9efc 100644 --- a/libgo/go/http/request_test.go +++ b/libgo/go/http/request_test.go @@ -49,7 +49,7 @@ func TestPostQuery(t *testing.T) { type stringMap map[string][]string type parseContentTypeTest struct { contentType stringMap - error bool + err bool } var parseContentTypeTests = []parseContentTypeTest{ @@ -58,7 +58,7 @@ var parseContentTypeTests = []parseContentTypeTest{ {contentType: stringMap{"Content-Type": {"text/plain; boundary="}}}, { contentType: stringMap{"Content-Type": {"application/unknown"}}, - error: true, + err: true, }, } @@ -70,10 +70,10 @@ func TestPostContentTypeParsing(t *testing.T) { Body: ioutil.NopCloser(bytes.NewBufferString("body")), } err := req.ParseForm() - if !test.error && err != nil { + if !test.err && err != nil { t.Errorf("test %d: Unexpected error: %v", i, err) } - if test.error && err == nil { + if test.err && err == nil { t.Errorf("test %d should have returned error", i) } } diff --git a/libgo/go/http/requestwrite_test.go b/libgo/go/http/requestwrite_test.go index 194f6dd..16593e9 100644 --- a/libgo/go/http/requestwrite_test.go +++ b/libgo/go/http/requestwrite_test.go @@ -6,10 +6,10 @@ package http import ( "bytes" + "errors" "fmt" "io" "io/ioutil" - "os" "strings" "testing" "url" @@ -24,7 +24,7 @@ type reqWriteTest struct { WantProxy string // Request.WriteProxy WantDump string // DumpRequest - WantError os.Error // wanted error from Request.Write + WantError error // wanted error from Request.Write } var reqWriteTests = []reqWriteTest{ @@ -292,7 +292,7 @@ var reqWriteTests = []reqWriteTest{ ContentLength: 10, // but we're going to send only 5 bytes }, Body: []byte("12345"), - WantError: os.NewError("http: Request.ContentLength=10 with Body length 5"), + WantError: errors.New("http: Request.ContentLength=10 with Body length 5"), }, // Request with a ContentLength of 4 but an 8 byte body. @@ -306,7 +306,7 @@ var reqWriteTests = []reqWriteTest{ ContentLength: 4, // but we're going to try to send 8 bytes }, Body: []byte("12345678"), - WantError: os.NewError("http: Request.ContentLength=4 with Body length 8"), + WantError: errors.New("http: Request.ContentLength=4 with Body length 8"), }, // Request with a 5 ContentLength and nil body. @@ -319,7 +319,7 @@ var reqWriteTests = []reqWriteTest{ ProtoMinor: 1, ContentLength: 5, // but we'll omit the body }, - WantError: os.NewError("http: Request.ContentLength=5 with nil Body"), + WantError: errors.New("http: Request.ContentLength=5 with nil Body"), }, // Verify that DumpRequest preserves the HTTP version number, doesn't add a Host, @@ -422,7 +422,7 @@ type closeChecker struct { closed bool } -func (rc *closeChecker) Close() os.Error { +func (rc *closeChecker) Close() error { rc.closed = true return nil } diff --git a/libgo/go/http/response.go b/libgo/go/http/response.go index 56c65b53..7be7150 100644 --- a/libgo/go/http/response.go +++ b/libgo/go/http/response.go @@ -8,9 +8,9 @@ package http import ( "bufio" + "errors" "io" "net/textproto" - "os" "strconv" "strings" "url" @@ -78,13 +78,13 @@ func (r *Response) Cookies() []*Cookie { return readSetCookies(r.Header) } -var ErrNoLocation = os.NewError("http: no Location header in response") +var ErrNoLocation = errors.New("http: no Location header in response") // Location returns the URL of the response's "Location" header, // if present. Relative redirects are resolved relative to // the Response's Request. ErrNoLocation is returned if no // Location header is present. -func (r *Response) Location() (*url.URL, os.Error) { +func (r *Response) Location() (*url.URL, error) { lv := r.Header.Get("Location") if lv == "" { return nil, ErrNoLocation @@ -101,7 +101,7 @@ func (r *Response) Location() (*url.URL, os.Error) { // reading resp.Body. After that call, clients can inspect // resp.Trailer to find key/value pairs included in the response // trailer. -func ReadResponse(r *bufio.Reader, req *Request) (resp *Response, err os.Error) { +func ReadResponse(r *bufio.Reader, req *Request) (resp *Response, err error) { tp := textproto.NewReader(r) resp = new(Response) @@ -112,7 +112,7 @@ func ReadResponse(r *bufio.Reader, req *Request) (resp *Response, err os.Error) // Parse the first line of the response. line, err := tp.ReadLine() if err != nil { - if err == os.EOF { + if err == io.EOF { err = io.ErrUnexpectedEOF } return nil, err @@ -186,7 +186,7 @@ func (r *Response) ProtoAtLeast(major, minor int) bool { // ContentLength // Header, values for non-canonical keys will have unpredictable behavior // -func (resp *Response) Write(w io.Writer) os.Error { +func (resp *Response) Write(w io.Writer) error { // RequestMethod should be upper-case if resp.Request != nil { diff --git a/libgo/go/http/response_test.go b/libgo/go/http/response_test.go index 86494bf..6a14179 100644 --- a/libgo/go/http/response_test.go +++ b/libgo/go/http/response_test.go @@ -10,7 +10,6 @@ import ( "compress/gzip" "crypto/rand" "fmt" - "os" "io" "io/ioutil" "reflect" @@ -301,7 +300,7 @@ func TestReadResponseCloseInMiddle(t *testing.T) { args = append([]interface{}{test.chunked, test.compressed}, args...) t.Fatalf("on test chunked=%v, compressed=%v: "+format, args...) } - checkErr := func(err os.Error, msg string) { + checkErr := func(err error, msg string) { if err == nil { return } @@ -320,7 +319,7 @@ func TestReadResponseCloseInMiddle(t *testing.T) { } if test.compressed { buf.WriteString("Content-Encoding: gzip\r\n") - var err os.Error + var err error wr, err = gzip.NewWriter(wr) checkErr(err, "gzip.NewWriter") } @@ -401,7 +400,7 @@ type responseLocationTest struct { location string // Response's Location header or "" requrl string // Response.Request.URL or "" want string - wantErr os.Error + wantErr error } var responseLocationTests = []responseLocationTest{ @@ -417,7 +416,7 @@ func TestLocationResponse(t *testing.T) { res.Header.Set("Location", tt.location) if tt.requrl != "" { res.Request = &Request{} - var err os.Error + var err error res.Request.URL, err = url.Parse(tt.requrl) if err != nil { t.Fatalf("bad test URL %q: %v", tt.requrl, err) @@ -430,7 +429,7 @@ func TestLocationResponse(t *testing.T) { t.Errorf("%d. err=nil; want %q", i, tt.wantErr) continue } - if g, e := err.String(), tt.wantErr.String(); g != e { + if g, e := err.Error(), tt.wantErr.Error(); g != e { t.Errorf("%d. err=%q; want %q", i, g, e) continue } diff --git a/libgo/go/http/reverseproxy.go b/libgo/go/http/reverseproxy.go index 3a63db0..9cd359f 100644 --- a/libgo/go/http/reverseproxy.go +++ b/libgo/go/http/reverseproxy.go @@ -10,7 +10,6 @@ import ( "io" "log" "net" - "os" "strings" "sync" "time" @@ -141,7 +140,7 @@ type maxLatencyWriter struct { done chan bool } -func (m *maxLatencyWriter) Write(p []byte) (n int, err os.Error) { +func (m *maxLatencyWriter) Write(p []byte) (n int, err error) { m.lk.Lock() defer m.lk.Unlock() if m.done == nil { diff --git a/libgo/go/http/serve_test.go b/libgo/go/http/serve_test.go index 2ff66d5..98e10d4 100644 --- a/libgo/go/http/serve_test.go +++ b/libgo/go/http/serve_test.go @@ -31,10 +31,10 @@ type oneConnListener struct { conn net.Conn } -func (l *oneConnListener) Accept() (c net.Conn, err os.Error) { +func (l *oneConnListener) Accept() (c net.Conn, err error) { c = l.conn if c == nil { - err = os.EOF + err = io.EOF return } err = nil @@ -42,7 +42,7 @@ func (l *oneConnListener) Accept() (c net.Conn, err os.Error) { return } -func (l *oneConnListener) Close() os.Error { +func (l *oneConnListener) Close() error { return nil } @@ -63,15 +63,15 @@ type testConn struct { writeBuf bytes.Buffer } -func (c *testConn) Read(b []byte) (int, os.Error) { +func (c *testConn) Read(b []byte) (int, error) { return c.readBuf.Read(b) } -func (c *testConn) Write(b []byte) (int, os.Error) { +func (c *testConn) Write(b []byte) (int, error) { return c.writeBuf.Write(b) } -func (c *testConn) Close() os.Error { +func (c *testConn) Close() error { return nil } @@ -83,15 +83,15 @@ func (c *testConn) RemoteAddr() net.Addr { return dummyAddr("remote-addr") } -func (c *testConn) SetTimeout(nsec int64) os.Error { +func (c *testConn) SetTimeout(nsec int64) error { return nil } -func (c *testConn) SetReadTimeout(nsec int64) os.Error { +func (c *testConn) SetReadTimeout(nsec int64) error { return nil } -func (c *testConn) SetWriteTimeout(nsec int64) os.Error { +func (c *testConn) SetWriteTimeout(nsec int64) error { return nil } @@ -108,7 +108,7 @@ func TestConsumingBodyOnNextConn(t *testing.T) { reqNum := 0 ch := make(chan *Request) - servech := make(chan os.Error) + servech := make(chan error) listener := &oneConnListener{conn} handler := func(res ResponseWriter, req *Request) { reqNum++ @@ -138,7 +138,7 @@ func TestConsumingBodyOnNextConn(t *testing.T) { req.Method, "POST") } - if serveerr := <-servech; serveerr != os.EOF { + if serveerr := <-servech; serveerr != io.EOF { t.Errorf("Serve returned %q; expected EOF", serveerr) } } @@ -273,8 +273,8 @@ func TestServerTimeouts(t *testing.T) { buf := make([]byte, 1) n, err := conn.Read(buf) latency := time.Nanoseconds() - t1 - if n != 0 || err != os.EOF { - t.Errorf("Read = %v, %v, wanted %v, %v", n, err, 0, os.EOF) + if n != 0 || err != io.EOF { + t.Errorf("Read = %v, %v, wanted %v, %v", n, err, 0, io.EOF) } if latency < second*0.20 /* fudge from 0.25 above */ { t.Errorf("got EOF after %d ns, want >= %d", latency, second*0.20) @@ -753,7 +753,7 @@ func TestServerUnreadRequestBodyLarge(t *testing.T) { func TestTimeoutHandler(t *testing.T) { sendHi := make(chan bool, 1) - writeErrors := make(chan os.Error, 1) + writeErrors := make(chan error, 1) sayHi := HandlerFunc(func(w ResponseWriter, r *Request) { <-sendHi _, werr := w.Write([]byte("hi")) @@ -992,7 +992,7 @@ func TestRequestLimit(t *testing.T) { type neverEnding byte -func (b neverEnding) Read(p []byte) (n int, err os.Error) { +func (b neverEnding) Read(p []byte) (n int, err error) { for i := range p { p[i] = byte(b) } @@ -1004,7 +1004,7 @@ type countReader struct { n *int64 } -func (cr countReader) Read(p []byte) (n int, err os.Error) { +func (cr countReader) Read(p []byte) (n int, err error) { n, err = cr.r.Read(p) *cr.n += int64(n) return @@ -1092,19 +1092,19 @@ func goTimeout(t *testing.T, ns int64, f func()) { } type errorListener struct { - errs []os.Error + errs []error } -func (l *errorListener) Accept() (c net.Conn, err os.Error) { +func (l *errorListener) Accept() (c net.Conn, err error) { if len(l.errs) == 0 { - return nil, os.EOF + return nil, io.EOF } err = l.errs[0] l.errs = l.errs[1:] return } -func (l *errorListener) Close() os.Error { +func (l *errorListener) Close() error { return nil } @@ -1116,13 +1116,13 @@ func TestAcceptMaxFds(t *testing.T) { log.SetOutput(ioutil.Discard) // is noisy otherwise defer log.SetOutput(os.Stderr) - ln := &errorListener{[]os.Error{ + ln := &errorListener{[]error{ &net.OpError{ - Op: "accept", - Error: os.Errno(syscall.EMFILE), + Op: "accept", + Err: os.Errno(syscall.EMFILE), }}} err := Serve(ln, HandlerFunc(HandlerFunc(func(ResponseWriter, *Request) {}))) - if err != os.EOF { + if err != io.EOF { t.Errorf("got error %v, want EOF", err) } } @@ -1138,11 +1138,11 @@ func BenchmarkClientServer(b *testing.B) { for i := 0; i < b.N; i++ { res, err := Get(ts.URL) if err != nil { - panic("Get: " + err.String()) + panic("Get: " + err.Error()) } all, err := ioutil.ReadAll(res.Body) if err != nil { - panic("ReadAll: " + err.String()) + panic("ReadAll: " + err.Error()) } body := string(all) if body != "Hello world.\n" { diff --git a/libgo/go/http/server.go b/libgo/go/http/server.go index 9792c60..f2a4f01 100644 --- a/libgo/go/http/server.go +++ b/libgo/go/http/server.go @@ -14,12 +14,12 @@ import ( "bytes" "crypto/rand" "crypto/tls" + "errors" "fmt" "io" "io/ioutil" "log" "net" - "os" "path" "runtime/debug" "strconv" @@ -31,10 +31,10 @@ import ( // Errors introduced by the HTTP server. var ( - ErrWriteAfterFlush = os.NewError("Conn.Write called after Flush") - ErrBodyNotAllowed = os.NewError("http: response status code does not allow body") - ErrHijacked = os.NewError("Conn has been hijacked") - ErrContentLength = os.NewError("Conn.Write wrote more than the declared Content-Length") + ErrWriteAfterFlush = errors.New("Conn.Write called after Flush") + ErrBodyNotAllowed = errors.New("http: 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") ) // Objects implementing the Handler interface can be @@ -60,7 +60,7 @@ type ResponseWriter interface { // Write writes the data to the connection as part of an HTTP reply. // If WriteHeader has not yet been called, Write calls WriteHeader(http.StatusOK) // before writing the data. - Write([]byte) (int, os.Error) + Write([]byte) (int, error) // WriteHeader sends an HTTP response header with status code. // If WriteHeader is not called explicitly, the first call to Write @@ -90,7 +90,7 @@ type Hijacker interface { // will not do anything else with the connection. // It becomes the caller's responsibility to manage // and close the connection. - Hijack() (net.Conn, *bufio.ReadWriter, os.Error) + Hijack() (net.Conn, *bufio.ReadWriter, error) } // A conn represents the server side of an HTTP connection. @@ -148,7 +148,7 @@ type writerOnly struct { io.Writer } -func (w *response) ReadFrom(src io.Reader) (n int64, err os.Error) { +func (w *response) ReadFrom(src io.Reader) (n int64, err error) { // Flush before checking w.chunking, as Flush will call // WriteHeader if it hasn't been called yet, and WriteHeader // is what sets w.chunking. @@ -169,7 +169,7 @@ func (w *response) ReadFrom(src io.Reader) (n int64, err os.Error) { const noLimit int64 = (1 << 63) - 1 // Create new connection from rwc. -func (srv *Server) newConn(rwc net.Conn) (c *conn, err os.Error) { +func (srv *Server) newConn(rwc net.Conn) (c *conn, err error) { c = new(conn) c.remoteAddr = rwc.RemoteAddr().String() c.server = srv @@ -202,9 +202,9 @@ type expectContinueReader struct { closed bool } -func (ecr *expectContinueReader) Read(p []byte) (n int, err os.Error) { +func (ecr *expectContinueReader) Read(p []byte) (n int, err error) { if ecr.closed { - return 0, os.NewError("http: Read after Close on request Body") + return 0, errors.New("http: Read after Close on request Body") } if !ecr.resp.wroteContinue && !ecr.resp.conn.hijacked { ecr.resp.wroteContinue = true @@ -214,7 +214,7 @@ func (ecr *expectContinueReader) Read(p []byte) (n int, err os.Error) { return ecr.readCloser.Read(p) } -func (ecr *expectContinueReader) Close() os.Error { +func (ecr *expectContinueReader) Close() error { ecr.closed = true return ecr.readCloser.Close() } @@ -225,10 +225,10 @@ func (ecr *expectContinueReader) Close() os.Error { // It is like time.RFC1123 but hard codes GMT as the time zone. const TimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT" -var errTooLarge = os.NewError("http: request too large") +var errTooLarge = errors.New("http: request too large") // Read next request from connection. -func (c *conn) readRequest() (w *response, err os.Error) { +func (c *conn) readRequest() (w *response, err error) { if c.hijacked { return nil, ErrHijacked } @@ -285,7 +285,7 @@ func (w *response) WriteHeader(code int) { var hasCL bool var contentLength int64 if clenStr := w.header.Get("Content-Length"); clenStr != "" { - var err os.Error + var err error contentLength, err = strconv.Atoi64(clenStr) if err == nil { hasCL = true @@ -439,7 +439,7 @@ func (w *response) bodyAllowed() bool { return w.status != StatusNotModified && w.req.Method != "HEAD" } -func (w *response) Write(data []byte) (n int, err os.Error) { +func (w *response) Write(data []byte) (n int, err error) { if w.conn.hijacked { log.Print("http: response.Write on hijacked connection") return 0, ErrHijacked @@ -663,7 +663,7 @@ func (c *conn) serve() { // Hijack implements the Hijacker.Hijack method. Our response is both a ResponseWriter // and a Hijacker. -func (w *response) Hijack() (rwc net.Conn, buf *bufio.ReadWriter, err os.Error) { +func (w *response) Hijack() (rwc net.Conn, buf *bufio.ReadWriter, err error) { if w.conn.hijacked { return nil, nil, ErrHijacked } @@ -943,7 +943,7 @@ func HandleFunc(pattern string, handler func(ResponseWriter, *Request)) { // creating a new service thread for each. The service threads // read requests and then call handler to reply to them. // Handler is typically nil, in which case the DefaultServeMux is used. -func Serve(l net.Listener, handler Handler) os.Error { +func Serve(l net.Listener, handler Handler) error { srv := &Server{Handler: handler} return srv.Serve(l) } @@ -960,7 +960,7 @@ type Server struct { // ListenAndServe listens on the TCP network address srv.Addr and then // calls Serve to handle requests on incoming connections. If // srv.Addr is blank, ":http" is used. -func (srv *Server) ListenAndServe() os.Error { +func (srv *Server) ListenAndServe() error { addr := srv.Addr if addr == "" { addr = ":http" @@ -975,7 +975,7 @@ func (srv *Server) ListenAndServe() os.Error { // Serve accepts incoming connections on the Listener l, creating a // new service thread for each. The service threads read requests and // then call srv.Handler to reply to them. -func (srv *Server) Serve(l net.Listener) os.Error { +func (srv *Server) Serve(l net.Listener) error { defer l.Close() for { rw, e := l.Accept() @@ -1028,7 +1028,7 @@ func (srv *Server) Serve(l net.Listener) os.Error { // log.Fatal("ListenAndServe: ", err.String()) // } // } -func ListenAndServe(addr string, handler Handler) os.Error { +func ListenAndServe(addr string, handler Handler) error { server := &Server{Addr: addr, Handler: handler} return server.ListenAndServe() } @@ -1061,7 +1061,7 @@ func ListenAndServe(addr string, handler Handler) os.Error { // } // // One can use generate_cert.go in crypto/tls to generate cert.pem and key.pem. -func ListenAndServeTLS(addr string, certFile string, keyFile string, handler Handler) os.Error { +func ListenAndServeTLS(addr string, certFile string, keyFile string, handler Handler) error { server := &Server{Addr: addr, Handler: handler} return server.ListenAndServeTLS(certFile, keyFile) } @@ -1075,7 +1075,7 @@ func ListenAndServeTLS(addr string, certFile string, keyFile string, handler Han // of the server's certificate followed by the CA's certificate. // // If srv.Addr is blank, ":https" is used. -func (s *Server) ListenAndServeTLS(certFile, keyFile string) os.Error { +func (s *Server) ListenAndServeTLS(certFile, keyFile string) error { addr := s.Addr if addr == "" { addr = ":https" @@ -1086,7 +1086,7 @@ func (s *Server) ListenAndServeTLS(certFile, keyFile string) os.Error { NextProtos: []string{"http/1.1"}, } - var err os.Error + var err error config.Certificates = make([]tls.Certificate, 1) config.Certificates[0], err = tls.LoadX509KeyPair(certFile, keyFile) if err != nil { @@ -1119,7 +1119,7 @@ func TimeoutHandler(h Handler, ns int64, msg string) Handler { // ErrHandlerTimeout is returned on ResponseWriter Write calls // in handlers which have timed out. -var ErrHandlerTimeout = os.NewError("http: Handler timeout") +var ErrHandlerTimeout = errors.New("http: Handler timeout") type timeoutHandler struct { handler Handler @@ -1167,7 +1167,7 @@ func (tw *timeoutWriter) Header() Header { return tw.w.Header() } -func (tw *timeoutWriter) Write(p []byte) (int, os.Error) { +func (tw *timeoutWriter) Write(p []byte) (int, error) { tw.mu.Lock() timedOut := tw.timedOut tw.mu.Unlock() diff --git a/libgo/go/http/transfer.go b/libgo/go/http/transfer.go index 868a114..6cb8625 100644 --- a/libgo/go/http/transfer.go +++ b/libgo/go/http/transfer.go @@ -7,10 +7,10 @@ package http import ( "bytes" "bufio" + "errors" "fmt" "io" "io/ioutil" - "os" "strconv" "strings" ) @@ -29,7 +29,7 @@ type transferWriter struct { Trailer Header } -func newTransferWriter(r interface{}) (t *transferWriter, err os.Error) { +func newTransferWriter(r interface{}) (t *transferWriter, err error) { t = &transferWriter{} // Extract relevant fields @@ -133,7 +133,7 @@ func (t *transferWriter) shouldSendContentLength() bool { return false } -func (t *transferWriter) WriteHeader(w io.Writer) (err os.Error) { +func (t *transferWriter) WriteHeader(w io.Writer) (err error) { if t.Close { _, err = io.WriteString(w, "Connection: close\r\n") if err != nil { @@ -181,7 +181,7 @@ func (t *transferWriter) WriteHeader(w io.Writer) (err os.Error) { return } -func (t *transferWriter) WriteBody(w io.Writer) (err os.Error) { +func (t *transferWriter) WriteBody(w io.Writer) (err error) { var ncopy int64 // Write body @@ -254,7 +254,7 @@ func bodyAllowedForStatus(status int) bool { } // msg is *Request or *Response. -func readTransfer(msg interface{}, r *bufio.Reader) (err os.Error) { +func readTransfer(msg interface{}, r *bufio.Reader) (err error) { t := &transferReader{} // Unify input @@ -360,7 +360,7 @@ func chunked(te []string) bool { return len(te) > 0 && te[0] == "chunked" } func isIdentity(te []string) bool { return len(te) == 1 && te[0] == "identity" } // Sanitize transfer encoding -func fixTransferEncoding(requestMethod string, header Header) ([]string, os.Error) { +func fixTransferEncoding(requestMethod string, header Header) ([]string, error) { raw, present := header["Transfer-Encoding"] if !present { return nil, nil @@ -409,7 +409,7 @@ func fixTransferEncoding(requestMethod string, header Header) ([]string, os.Erro // Determine the expected body length, using RFC 2616 Section 4.4. This // function is not a method, because ultimately it should be shared by // ReadResponse and ReadRequest. -func fixLength(isResponse bool, status int, requestMethod string, header Header, te []string) (int64, os.Error) { +func fixLength(isResponse bool, status int, requestMethod string, header Header, te []string) (int64, error) { // Logic based on response type or status if noBodyExpected(requestMethod) { @@ -482,7 +482,7 @@ func shouldClose(major, minor int, header Header) bool { } // Parse the trailer header -func fixTrailer(header Header, te []string) (Header, os.Error) { +func fixTrailer(header Header, te []string) (Header, error) { raw := header.Get("Trailer") if raw == "" { return nil, nil @@ -526,16 +526,16 @@ type body struct { // the body has been closed. This typically happens when the body is // read after an HTTP Handler calls WriteHeader or Write on its // ResponseWriter. -var ErrBodyReadAfterClose = os.NewError("http: invalid Read on closed request Body") +var ErrBodyReadAfterClose = errors.New("http: invalid Read on closed request Body") -func (b *body) Read(p []byte) (n int, err os.Error) { +func (b *body) Read(p []byte) (n int, err error) { if b.closed { return 0, ErrBodyReadAfterClose } return b.Reader.Read(p) } -func (b *body) Close() os.Error { +func (b *body) Close() error { if b.closed { return nil } diff --git a/libgo/go/http/transport.go b/libgo/go/http/transport.go index 1d4433d..c7041cb 100644 --- a/libgo/go/http/transport.go +++ b/libgo/go/http/transport.go @@ -14,6 +14,7 @@ import ( "compress/gzip" "crypto/tls" "encoding/base64" + "errors" "fmt" "io" "io/ioutil" @@ -52,12 +53,12 @@ type Transport struct { // Request. If the function returns a non-nil error, the // request is aborted with the provided error. // If Proxy is nil or returns a nil *URL, no proxy is used. - Proxy func(*Request) (*url.URL, os.Error) + Proxy func(*Request) (*url.URL, error) // Dial specifies the dial function for creating TCP // connections. // If Dial is nil, net.Dial is used. - Dial func(net, addr string) (c net.Conn, err os.Error) + Dial func(net, addr string) (c net.Conn, err error) // TLSClientConfig specifies the TLS configuration to use with // tls.Client. If nil, the default configuration is used. @@ -76,7 +77,7 @@ type Transport struct { // given request, as indicated by the environment variables // $HTTP_PROXY and $NO_PROXY (or $http_proxy and $no_proxy). // Either URL or an error is returned. -func ProxyFromEnvironment(req *Request) (*url.URL, os.Error) { +func ProxyFromEnvironment(req *Request) (*url.URL, error) { proxy := getenvEitherCase("HTTP_PROXY") if proxy == "" { return nil, nil @@ -86,12 +87,12 @@ func ProxyFromEnvironment(req *Request) (*url.URL, os.Error) { } proxyURL, err := url.ParseRequest(proxy) if err != nil { - return nil, os.NewError("invalid proxy address") + return nil, errors.New("invalid proxy address") } if proxyURL.Host == "" { proxyURL, err = url.ParseRequest("http://" + proxy) if err != nil { - return nil, os.NewError("invalid proxy address") + return nil, errors.New("invalid proxy address") } } return proxyURL, nil @@ -99,8 +100,8 @@ func ProxyFromEnvironment(req *Request) (*url.URL, os.Error) { // ProxyURL returns a proxy function (for use in a Transport) // that always returns the same URL. -func ProxyURL(fixedURL *url.URL) func(*Request) (*url.URL, os.Error) { - return func(*Request) (*url.URL, os.Error) { +func ProxyURL(fixedURL *url.URL) func(*Request) (*url.URL, error) { + return func(*Request) (*url.URL, error) { return fixedURL, nil } } @@ -120,12 +121,12 @@ func (tr *transportRequest) extraHeaders() Header { } // RoundTrip implements the RoundTripper interface. -func (t *Transport) RoundTrip(req *Request) (resp *Response, err os.Error) { +func (t *Transport) RoundTrip(req *Request) (resp *Response, err error) { if req.URL == nil { - return nil, os.NewError("http: nil Request.URL") + return nil, errors.New("http: nil Request.URL") } if req.Header == nil { - return nil, os.NewError("http: nil Request.Header") + return nil, errors.New("http: nil Request.Header") } if req.URL.Scheme != "http" && req.URL.Scheme != "https" { t.lk.Lock() @@ -207,13 +208,13 @@ func getenvEitherCase(k string) string { return os.Getenv(strings.ToLower(k)) } -func (t *Transport) connectMethodForRequest(treq *transportRequest) (*connectMethod, os.Error) { +func (t *Transport) connectMethodForRequest(treq *transportRequest) (*connectMethod, error) { cm := &connectMethod{ targetScheme: treq.URL.Scheme, targetAddr: canonicalAddr(treq.URL), } if t.Proxy != nil { - var err os.Error + var err error cm.proxyURL, err = t.Proxy(treq.Request) if err != nil { return nil, err @@ -285,7 +286,7 @@ func (t *Transport) getIdleConn(cm *connectMethod) (pconn *persistConn) { return } -func (t *Transport) dial(network, addr string) (c net.Conn, err os.Error) { +func (t *Transport) dial(network, addr string) (c net.Conn, err error) { if t.Dial != nil { return t.Dial(network, addr) } @@ -296,7 +297,7 @@ func (t *Transport) dial(network, addr string) (c net.Conn, err os.Error) { // specified in the connectMethod. This includes doing a proxy CONNECT // and/or setting up TLS. If this doesn't return an error, the persistConn // is ready to write requests to. -func (t *Transport) getConn(cm *connectMethod) (*persistConn, os.Error) { +func (t *Transport) getConn(cm *connectMethod) (*persistConn, error) { if pc := t.getIdleConn(cm); pc != nil { return pc, nil } @@ -352,7 +353,7 @@ func (t *Transport) getConn(cm *connectMethod) (*persistConn, os.Error) { if resp.StatusCode != 200 { f := strings.SplitN(resp.Status, " ", 2) conn.Close() - return nil, os.NewError(f[1]) + return nil, errors.New(f[1]) } } @@ -500,10 +501,10 @@ func (pc *persistConn) expectingResponse() bool { return pc.numExpectedResponses > 0 } -var remoteSideClosedFunc func(os.Error) bool // or nil to use default +var remoteSideClosedFunc func(error) bool // or nil to use default -func remoteSideClosed(err os.Error) bool { - if err == os.EOF || err == os.EINVAL { +func remoteSideClosed(err error) bool { + if err == io.EOF || err == os.EINVAL { return true } if remoteSideClosedFunc != nil { @@ -532,7 +533,7 @@ func (pc *persistConn) readLoop() { } rc := <-pc.reqch - resp, err := pc.cc.readUsing(rc.req, func(buf *bufio.Reader, forReq *Request) (*Response, os.Error) { + resp, err := pc.cc.readUsing(rc.req, func(buf *bufio.Reader, forReq *Request) (*Response, error) { resp, err := ReadResponse(buf, forReq) if err != nil || resp.ContentLength == 0 { return resp, err @@ -599,7 +600,7 @@ func (pc *persistConn) readLoop() { type responseAndError struct { res *Response - err os.Error + err error } type requestAndChan struct { @@ -612,7 +613,7 @@ type requestAndChan struct { addedGzip bool } -func (pc *persistConn) roundTrip(req *transportRequest) (resp *Response, err os.Error) { +func (pc *persistConn) roundTrip(req *transportRequest) (resp *Response, err error) { if pc.mutateHeaderFunc != nil { pc.mutateHeaderFunc(req.extraHeaders()) } @@ -634,7 +635,7 @@ func (pc *persistConn) roundTrip(req *transportRequest) (resp *Response, err os. pc.numExpectedResponses++ pc.lk.Unlock() - pc.cc.writeReq = func(r *Request, w io.Writer) os.Error { + pc.cc.writeReq = func(r *Request, w io.Writer) error { return r.write(w, pc.isProxy, req.extra) } @@ -691,19 +692,19 @@ type bodyEOFSignal struct { isClosed bool } -func (es *bodyEOFSignal) Read(p []byte) (n int, err os.Error) { +func (es *bodyEOFSignal) Read(p []byte) (n int, err error) { n, err = es.body.Read(p) if es.isClosed && n > 0 { panic("http: unexpected bodyEOFSignal Read after Close; see issue 1725") } - if err == os.EOF && es.fn != nil { + if err == io.EOF && es.fn != nil { es.fn() es.fn = nil } return } -func (es *bodyEOFSignal) Close() (err os.Error) { +func (es *bodyEOFSignal) Close() (err error) { if es.isClosed { return nil } @@ -721,7 +722,7 @@ type readFirstCloseBoth struct { io.Closer } -func (r *readFirstCloseBoth) Close() os.Error { +func (r *readFirstCloseBoth) Close() error { if err := r.ReadCloser.Close(); err != nil { r.Closer.Close() return err @@ -737,7 +738,7 @@ type discardOnCloseReadCloser struct { io.ReadCloser } -func (d *discardOnCloseReadCloser) Close() os.Error { +func (d *discardOnCloseReadCloser) Close() error { io.Copy(ioutil.Discard, d.ReadCloser) // ignore errors; likely invalid or already closed return d.ReadCloser.Close() } diff --git a/libgo/go/http/transport_test.go b/libgo/go/http/transport_test.go index f3162b9..b2d0eba 100644 --- a/libgo/go/http/transport_test.go +++ b/libgo/go/http/transport_test.go @@ -15,7 +15,6 @@ import ( "http/httptest" "io" "io/ioutil" - "os" "strconv" "strings" "testing" @@ -77,7 +76,7 @@ func TestTransportConnectionCloseOnResponse(t *testing.T) { fetch := func(n int) string { req := new(Request) - var err os.Error + var err error req.URL, err = url.Parse(ts.URL + fmt.Sprintf("/?close=%v", connectionClose)) if err != nil { t.Fatalf("URL parse error: %v", err) @@ -119,7 +118,7 @@ func TestTransportConnectionCloseOnRequest(t *testing.T) { fetch := func(n int) string { req := new(Request) - var err os.Error + var err error req.URL, err = url.Parse(ts.URL) if err != nil { t.Fatalf("URL parse error: %v", err) @@ -575,7 +574,7 @@ func TestTransportGzipRecursive(t *testing.T) { type fooProto struct{} -func (fooProto) RoundTrip(req *Request) (*Response, os.Error) { +func (fooProto) RoundTrip(req *Request) (*Response, error) { res := &Response{ Status: "200 OK", StatusCode: 200, diff --git a/libgo/go/http/transport_windows.go b/libgo/go/http/transport_windows.go index 1ae7d83..e0dc857 100644 --- a/libgo/go/http/transport_windows.go +++ b/libgo/go/http/transport_windows.go @@ -10,9 +10,9 @@ import ( ) func init() { - remoteSideClosedFunc = func(err os.Error) (out bool) { + remoteSideClosedFunc = func(err error) (out bool) { op, ok := err.(*net.OpError) - if ok && op.Op == "WSARecv" && op.Net == "tcp" && op.Error == os.Errno(10058) { + if ok && op.Op == "WSARecv" && op.Net == "tcp" && op.Err == os.Errno(10058) { // TODO(bradfitz): find the symbol for 10058 return true } |