aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Gerrand <adg@golang.org>2010-06-08 01:28:40 +0200
committerAndrew Gerrand <adg@golang.org>2010-06-08 01:28:40 +0200
commit9b3c743f827e4eeacc0e85dc0d88e7b252445bec (patch)
treead60bc756f3f8fed9b2391eae12e62384c142a63
parent7bc03718f432c7b6cb0e61141013f9b24733dd7c (diff)
downloadgo-9b3c743f827e4eeacc0e85dc0d88e7b252445bec.tar.gz
go-9b3c743f827e4eeacc0e85dc0d88e7b252445bec.zip
http: add Head function for making HTTP HEAD requests
R=rsc CC=golang-dev https://golang.org/cl/1581041
-rw-r--r--src/pkg/http/client.go14
-rw-r--r--src/pkg/http/client_test.go10
2 files changed, 23 insertions, 1 deletions
diff --git a/src/pkg/http/client.go b/src/pkg/http/client.go
index fe61d20733..54487dac2f 100644
--- a/src/pkg/http/client.go
+++ b/src/pkg/http/client.go
@@ -130,7 +130,6 @@ func Get(url string) (r *Response, finalURL string, err os.Error) {
return
}
-
// Post issues a POST to the specified URL.
//
// 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)
}
+// 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 {
io.Reader
}
diff --git a/src/pkg/http/client_test.go b/src/pkg/http/client_test.go
index 6787825d81..a916b12e24 100644
--- a/src/pkg/http/client_test.go
+++ b/src/pkg/http/client_test.go
@@ -28,3 +28,13 @@ func TestClient(t *testing.T) {
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.")
+ }
+}