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
cdb0bbf4
Commit
cdb0bbf4
authored
Jan 13, 2011
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
http: handle HEAD requests correctly
R=r, r2 CC=golang-dev
https://golang.org/cl/3939042
parent
97025ebf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
7 deletions
+11
-7
fs.go
src/pkg/http/fs.go
+3
-1
server.go
src/pkg/http/server.go
+8
-6
No files found.
src/pkg/http/fs.go
View file @
cdb0bbf4
...
...
@@ -174,7 +174,9 @@ func serveFile(w ResponseWriter, r *Request, name string, redirect bool) {
w
.
WriteHeader
(
code
)
io
.
Copyn
(
w
,
f
,
size
)
if
r
.
Method
!=
"HEAD"
{
io
.
Copyn
(
w
,
f
,
size
)
}
}
// ServeFile replies to the request with the contents of the named file or directory.
...
...
src/pkg/http/server.go
View file @
cdb0bbf4
...
...
@@ -181,7 +181,9 @@ func (c *conn) readRequest() (w *response, err os.Error) {
w
.
SetHeader
(
"Content-Type"
,
"text/html; charset=utf-8"
)
w
.
SetHeader
(
"Date"
,
time
.
UTC
()
.
Format
(
TimeFormat
))
if
req
.
ProtoAtLeast
(
1
,
1
)
{
if
req
.
Method
==
"HEAD"
{
// do nothing
}
else
if
req
.
ProtoAtLeast
(
1
,
1
)
{
// HTTP/1.1 or greater: use chunked transfer encoding
// to avoid closing the connection at EOF.
w
.
chunking
=
true
...
...
@@ -268,7 +270,7 @@ func (w *response) Write(data []byte) (n int, err os.Error) {
return
0
,
nil
}
if
w
.
status
==
StatusNotModified
{
if
w
.
status
==
StatusNotModified
||
w
.
req
.
Method
==
"HEAD"
{
// Must not have body.
return
0
,
ErrBodyNotAllowed
}
...
...
@@ -495,11 +497,11 @@ func Redirect(w ResponseWriter, r *Request, url string, code int) {
// RFC2616 recommends that a short note "SHOULD" be included in the
// response because older user agents may not understand 301/307.
note
:=
"<a href=
\"
"
+
htmlEscape
(
url
)
+
"
\"
>"
+
statusText
[
code
]
+
"</a>.
\n
"
if
r
.
Method
==
"POST"
{
note
=
""
// Shouldn't send the response for POST or HEAD; that leaves GET.
if
r
.
Method
==
"GET"
{
note
:=
"<a href=
\"
"
+
htmlEscape
(
url
)
+
"
\"
>"
+
statusText
[
code
]
+
"</a>.
\n
"
fmt
.
Fprintln
(
w
,
note
)
}
fmt
.
Fprintln
(
w
,
note
)
}
func
htmlEscape
(
s
string
)
string
{
...
...
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