]> Cypherpunks repositories - gostls13.git/commitdiff
http: export parseHTTPVersion.
authorDavid Symonds <dsymonds@golang.org>
Tue, 1 Mar 2011 11:38:18 +0000 (22:38 +1100)
committerDavid Symonds <dsymonds@golang.org>
Tue, 1 Mar 2011 11:38:18 +0000 (22:38 +1100)
R=rsc, adg
CC=golang-dev
https://golang.org/cl/4244045

src/pkg/http/request.go
src/pkg/http/response.go

index f7ea758bb43458949003c2eba795a4ae5b9cde53..0fd5df4e3b527237602e45addc5dc6c383a2cb16 100644 (file)
@@ -315,8 +315,9 @@ func atoi(s string, i int) (n, i1 int, ok bool) {
        return n, i, true
 }
 
-// Parse HTTP version: "HTTP/1.2" -> (1, 2, true).
-func parseHTTPVersion(vers string) (int, int, bool) {
+// ParseHTTPVersion parses a HTTP version string.
+// "HTTP/1.2" returns (1, 2, true).
+func ParseHTTPVersion(vers string) (major, minor int, ok bool) {
        if len(vers) < 5 || vers[0:5] != "HTTP/" {
                return 0, 0, false
        }
@@ -324,7 +325,6 @@ func parseHTTPVersion(vers string) (int, int, bool) {
        if !ok || i >= len(vers) || vers[i] != '.' {
                return 0, 0, false
        }
-       var minor int
        minor, i, ok = atoi(vers, i+1)
        if !ok || i != len(vers) {
                return 0, 0, false
@@ -416,7 +416,7 @@ func ReadRequest(b *bufio.Reader) (req *Request, err os.Error) {
        }
        req.Method, req.RawURL, req.Proto = f[0], f[1], f[2]
        var ok bool
-       if req.ProtoMajor, req.ProtoMinor, ok = parseHTTPVersion(req.Proto); !ok {
+       if req.ProtoMajor, req.ProtoMinor, ok = ParseHTTPVersion(req.Proto); !ok {
                return nil, &badStringError{"malformed HTTP version", req.Proto}
        }
 
index 5346d4a50469e3c9f54b5c9682f0f0e4348c8ca5..3f919c86a3cb775baa6f051439a5d04376594c64 100644 (file)
@@ -106,7 +106,7 @@ func ReadResponse(r *bufio.Reader, requestMethod string) (resp *Response, err os
 
        resp.Proto = f[0]
        var ok bool
-       if resp.ProtoMajor, resp.ProtoMinor, ok = parseHTTPVersion(resp.Proto); !ok {
+       if resp.ProtoMajor, resp.ProtoMinor, ok = ParseHTTPVersion(resp.Proto); !ok {
                return nil, &badStringError{"malformed HTTP version", resp.Proto}
        }