Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
1e85f41f
Commit
1e85f41f
authored
Nov 28, 2011
by
Brad Fitzpatrick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
http: fix sniffing bug causing short writes
R=rsc CC=golang-dev
https://golang.org/cl/5442045
parent
7606079d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
1 deletion
+24
-1
src/pkg/net/http/server.go
src/pkg/net/http/server.go
+1
-1
src/pkg/net/http/sniff_test.go
src/pkg/net/http/sniff_test.go
+23
-0
No files found.
src/pkg/net/http/server.go
View file @
1e85f41f
...
...
@@ -467,7 +467,7 @@ func (w *response) Write(data []byte) (n int, err error) {
// determine the content type. Accumulate the
// initial writes in w.conn.body.
// Cap m so that append won't allocate.
m
:
=
cap
(
w
.
conn
.
body
)
-
len
(
w
.
conn
.
body
)
m
=
cap
(
w
.
conn
.
body
)
-
len
(
w
.
conn
.
body
)
if
m
>
len
(
data
)
{
m
=
len
(
data
)
}
...
...
src/pkg/net/http/sniff_test.go
View file @
1e85f41f
...
...
@@ -6,12 +6,14 @@ package http_test
import
(
"bytes"
"fmt"
"io"
"io/ioutil"
"log"
.
"net/http"
"net/http/httptest"
"strconv"
"strings"
"testing"
)
...
...
@@ -112,3 +114,24 @@ func TestContentTypeWithCopy(t *testing.T) {
}
resp
.
Body
.
Close
()
}
func
TestSniffWriteSize
(
t
*
testing
.
T
)
{
ts
:=
httptest
.
NewServer
(
HandlerFunc
(
func
(
w
ResponseWriter
,
r
*
Request
)
{
size
,
_
:=
strconv
.
Atoi
(
r
.
FormValue
(
"size"
))
written
,
err
:=
io
.
WriteString
(
w
,
strings
.
Repeat
(
"a"
,
size
))
if
err
!=
nil
{
t
.
Errorf
(
"write of %d bytes: %v"
,
size
,
err
)
return
}
if
written
!=
size
{
t
.
Errorf
(
"write of %d bytes wrote %d bytes"
,
size
,
written
)
}
}))
defer
ts
.
Close
()
for
_
,
size
:=
range
[]
int
{
0
,
1
,
200
,
600
,
999
,
1000
,
1023
,
1024
,
512
<<
10
,
1
<<
20
}
{
_
,
err
:=
Get
(
fmt
.
Sprintf
(
"%s/?size=%d"
,
ts
.
URL
,
size
))
if
err
!=
nil
{
t
.
Fatalf
(
"size %d: %v"
,
size
,
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