Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
9b3c743f
Commit
9b3c743f
authored
Jun 07, 2010
by
Andrew Gerrand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
http: add Head function for making HTTP HEAD requests
R=rsc CC=golang-dev
https://golang.org/cl/1581041
parent
7bc03718
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
1 deletion
+23
-1
client.go
src/pkg/http/client.go
+13
-1
client_test.go
src/pkg/http/client_test.go
+10
-0
No files found.
src/pkg/http/client.go
View file @
9b3c743f
...
@@ -130,7 +130,6 @@ func Get(url string) (r *Response, finalURL string, err os.Error) {
...
@@ -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
...
@@ -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
}
}
...
...
src/pkg/http/client_test.go
View file @
9b3c743f
...
@@ -28,3 +28,13 @@ func TestClient(t *testing.T) {
...
@@ -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."
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment