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
e3b94edc
Commit
e3b94edc
authored
Feb 19, 2010
by
Petar Maymounkov
Committed by
Russ Cox
Feb 19, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
http: do not edit Response.ContentLength in Response.Write
R=rsc CC=golang-dev
https://golang.org/cl/207061
parent
80a14df1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
6 deletions
+7
-6
response.go
src/pkg/http/response.go
+7
-6
No files found.
src/pkg/http/response.go
View file @
e3b94edc
...
...
@@ -398,11 +398,12 @@ func (resp *Response) Write(w io.Writer) os.Error {
io
.
WriteString
(
w
,
strconv
.
Itoa
(
resp
.
StatusCode
)
+
" "
+
text
+
"
\r\n
"
)
// Sanitize the field triple (Body, ContentLength, TransferEncoding)
contentLength
:=
resp
.
ContentLength
if
noBodyExpected
(
resp
.
RequestMethod
)
{
resp
.
Body
=
nil
resp
.
TransferEncoding
=
nil
// resp.ContentLength is expected to hold Content-Length
if
resp
.
C
ontentLength
<
0
{
if
c
ontentLength
<
0
{
return
ErrMissingContentLength
}
}
else
{
...
...
@@ -410,9 +411,9 @@ func (resp *Response) Write(w io.Writer) os.Error {
resp
.
TransferEncoding
=
nil
}
if
chunked
(
resp
.
TransferEncoding
)
{
resp
.
C
ontentLength
=
-
1
c
ontentLength
=
-
1
}
else
if
resp
.
Body
==
nil
{
// no chunking, no body
resp
.
C
ontentLength
=
0
c
ontentLength
=
0
}
}
...
...
@@ -422,9 +423,9 @@ func (resp *Response) Write(w io.Writer) os.Error {
if
chunked
(
resp
.
TransferEncoding
)
{
io
.
WriteString
(
w
,
"Transfer-Encoding: chunked
\r\n
"
)
}
else
{
if
resp
.
C
ontentLength
>
0
||
resp
.
RequestMethod
==
"HEAD"
{
if
c
ontentLength
>
0
||
resp
.
RequestMethod
==
"HEAD"
{
io
.
WriteString
(
w
,
"Content-Length: "
)
io
.
WriteString
(
w
,
strconv
.
Itoa64
(
resp
.
C
ontentLength
)
+
"
\r\n
"
)
io
.
WriteString
(
w
,
strconv
.
Itoa64
(
c
ontentLength
)
+
"
\r\n
"
)
}
}
if
resp
.
Header
!=
nil
{
...
...
@@ -477,7 +478,7 @@ func (resp *Response) Write(w io.Writer) os.Error {
err
=
cw
.
Close
()
}
}
else
{
_
,
err
=
io
.
Copy
(
w
,
io
.
LimitReader
(
resp
.
Body
,
resp
.
C
ontentLength
))
_
,
err
=
io
.
Copy
(
w
,
io
.
LimitReader
(
resp
.
Body
,
c
ontentLength
))
}
if
err
!=
nil
{
return
err
...
...
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