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
99e5d48e
Commit
99e5d48e
authored
Jul 22, 2011
by
David Symonds
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
http: clarify use of w.conn.body in Write when sniffing.
R=gri, r, r, rsc CC=golang-dev
https://golang.org/cl/4794047
parent
3e79c958
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
7 deletions
+9
-7
server.go
src/pkg/http/server.go
+9
-7
No files found.
src/pkg/http/server.go
View file @
99e5d48e
...
...
@@ -359,8 +359,7 @@ func (w *response) sniff() {
w
.
needSniff
=
false
data
:=
w
.
conn
.
body
fmt
.
Fprintf
(
w
.
conn
.
buf
,
"Content-Type: %s
\r\n
"
,
DetectContentType
(
data
))
io
.
WriteString
(
w
.
conn
.
buf
,
"
\r\n
"
)
fmt
.
Fprintf
(
w
.
conn
.
buf
,
"Content-Type: %s
\r\n\r\n
"
,
DetectContentType
(
data
))
if
len
(
data
)
==
0
{
return
...
...
@@ -408,10 +407,14 @@ func (w *response) Write(data []byte) (n int, err os.Error) {
// We need to sniff the beginning of the output to
// determine the content type. Accumulate the
// initial writes in w.conn.body.
body
:=
w
.
conn
.
body
m
=
copy
(
body
[
len
(
body
)
:
cap
(
body
)],
data
)
w
.
conn
.
body
=
body
[
:
len
(
body
)
+
m
]
if
m
==
len
(
data
)
{
// Cap m so that append won't allocate.
m
:=
cap
(
w
.
conn
.
body
)
-
len
(
w
.
conn
.
body
)
if
m
>
len
(
data
)
{
m
=
len
(
data
)
}
w
.
conn
.
body
=
append
(
w
.
conn
.
body
,
data
[
:
m
]
...
)
data
=
data
[
m
:
]
if
len
(
data
)
==
0
{
// Copied everything into the buffer.
// Wait for next write.
return
m
,
nil
...
...
@@ -423,7 +426,6 @@ func (w *response) Write(data []byte) (n int, err os.Error) {
// of the data as a normal Write.
// Calling sniff clears needSniff.
w
.
sniff
()
data
=
data
[
m
:
]
}
// TODO(rsc): if chunking happened after the buffering,
...
...
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