]> Cypherpunks repositories - gostls13.git/commitdiff
http: set method GET on Get() requests
authorBrad Fitzpatrick <bradfitz@golang.org>
Wed, 23 Feb 2011 23:03:30 +0000 (15:03 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 23 Feb 2011 23:03:30 +0000 (15:03 -0800)
R=adg, bradfitzwork
CC=golang-dev
https://golang.org/cl/4229042

src/pkg/http/client.go
src/pkg/http/client_test.go

index 116b926433b616c5ba8fcb148cf5826ff1a2bfdb..c2e2d3eed16f39fce51b58ff852ab053a203d1d5 100644 (file)
@@ -171,6 +171,9 @@ func (c *Client) Get(url string) (r *Response, finalURL string, err os.Error) {
                }
 
                var req Request
+               req.Method = "GET"
+               req.ProtoMajor = 1
+               req.ProtoMinor = 1
                if base == nil {
                        req.URL, err = ParseURL(url)
                } else {
index 013653a829695d63dd48b0da3ba94aad4b438c92..a541ffc08edd2a072fef19998ae77b7953cd8444 100644 (file)
@@ -8,6 +8,7 @@ package http
 
 import (
        "io/ioutil"
+       "os"
        "strings"
        "testing"
 )
@@ -38,3 +39,25 @@ func TestClientHead(t *testing.T) {
                t.Error("Last-Modified header not found.")
        }
 }
+
+type recordingTransport struct {
+       req *Request
+}
+
+func (t *recordingTransport) Do(req *Request) (resp *Response, err os.Error) {
+       t.req = req
+       return nil, os.NewError("dummy impl")
+}
+
+func TestGetRequestFormat(t *testing.T) {
+       tr := &recordingTransport{}
+       client := &Client{transport: tr}
+       url := "http://dummy.faketld/"
+       client.Get(url) // Note: doesn't hit network
+       if tr.req.Method != "GET" {
+               t.Fatalf("expected method %q; got %q", "GET", tr.req.Method)
+       }
+       if tr.req.URL.String() != url {
+               t.Fatalf("expected URL %q; got %q", url, tr.req.URL.String())
+       }
+}