]> Cypherpunks repositories - gostls13.git/commitdiff
Don't prefix Url.Path with a slash in Request.write,
authorDavid Symonds <dsymonds@golang.org>
Mon, 22 Jun 2009 21:50:12 +0000 (14:50 -0700)
committerDavid Symonds <dsymonds@golang.org>
Mon, 22 Jun 2009 21:50:12 +0000 (14:50 -0700)
because Url.Path already starts with one.
Avoid crashing in Request.ParseForm if there is no body.

R=rsc
APPROVED=rsc
DELTA=5  (4 added, 0 deleted, 1 changed)
OCL=30552
CL=30607

src/pkg/http/request.go

index a0207ea71df5aac7fa347c0ed47d3b0ba23740fd..c12110eb3f6f2c609a501b08fd875f516c0fa15b 100644 (file)
@@ -36,6 +36,7 @@ var (
        HeaderTooLong = &ProtocolError{"http header too long"};
        BadContentLength = &ProtocolError{"invalid content length"};
        ShortEntityBody = &ProtocolError{"entity body too short"};
+       NoEntityBody = &ProtocolError{"no entity body"};
        BadHeader = &ProtocolError{"malformed http header"};
        BadRequest = &ProtocolError{"invalid http request"};
        BadHTTPVersion = &ProtocolError{"unsupported http version"};
@@ -124,7 +125,7 @@ const defaultUserAgent = "http.Client";
 // Write an HTTP request -- header and body -- in wire format.
 // See Send for a list of which Request fields we use.
 func (req *Request) write(w io.Writer) os.Error {
-       uri := "/" + URLEscape(req.Url.Path);
+       uri := URLEscape(req.Url.Path);
        if req.Url.RawQuery != "" {
                uri += "?" + req.Url.RawQuery;
        }
@@ -493,6 +494,9 @@ func parseForm(body string) (data map[string] *vector.StringVector, err os.Error
 
 // ParseForm parses the request body as a form.
 func (r *Request) ParseForm() (err os.Error) {
+       if r.Body == nil {
+               return NoEntityBody
+       }
        ct, ok := r.Header["Content-Type"];
        if !ok {
                ct = "application/x-www-form-urlencoded";  // default