mirror of
https://github.com/golang/go
synced 2024-11-22 05:54:40 -07:00
http: add Head function for making HTTP HEAD requests
R=rsc CC=golang-dev https://golang.org/cl/1581041
This commit is contained in:
parent
7bc03718f4
commit
9b3c743f82
@ -130,7 +130,6 @@ func Get(url string) (r *Response, finalURL string, err os.Error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Post issues a POST to the specified URL.
|
// Post issues a POST to the specified URL.
|
||||||
//
|
//
|
||||||
// Caller should close r.Body when done reading it.
|
// Caller should close r.Body when done reading it.
|
||||||
@ -154,6 +153,19 @@ func Post(url string, bodyType string, body io.Reader) (r *Response, err os.Erro
|
|||||||
return send(&req)
|
return send(&req)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Head issues a HEAD to the specified URL.
|
||||||
|
func Head(url string) (r *Response, err os.Error) {
|
||||||
|
var req Request
|
||||||
|
req.Method = "HEAD"
|
||||||
|
if req.URL, err = ParseURL(url); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if r, err = send(&req); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
type nopCloser struct {
|
type nopCloser struct {
|
||||||
io.Reader
|
io.Reader
|
||||||
}
|
}
|
||||||
|
@ -28,3 +28,13 @@ func TestClient(t *testing.T) {
|
|||||||
t.Errorf("Incorrect page body (did not begin with User-agent): %q", s)
|
t.Errorf("Incorrect page body (did not begin with User-agent): %q", s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestClientHead(t *testing.T) {
|
||||||
|
r, err := Head("http://www.google.com/robots.txt")
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
if _, ok := r.Header["Last-Modified"]; !ok {
|
||||||
|
t.Error("Last-Modified header not found.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user