mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
http: set method GET on Get() requests
R=adg, bradfitzwork CC=golang-dev https://golang.org/cl/4229042
This commit is contained in:
parent
8b8d5e9e00
commit
c7978584c3
2 changed files with 26 additions and 0 deletions
|
|
@ -171,6 +171,9 @@ func (c *Client) Get(url string) (r *Response, finalURL string, err os.Error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var req Request
|
var req Request
|
||||||
|
req.Method = "GET"
|
||||||
|
req.ProtoMajor = 1
|
||||||
|
req.ProtoMinor = 1
|
||||||
if base == nil {
|
if base == nil {
|
||||||
req.URL, err = ParseURL(url)
|
req.URL, err = ParseURL(url)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ package http
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
@ -38,3 +39,25 @@ func TestClientHead(t *testing.T) {
|
||||||
t.Error("Last-Modified header not found.")
|
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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue