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
950fa935
Commit
950fa935
authored
May 21, 2013
by
Brad Fitzpatrick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net/http: add another Hijacker test
R=dsymonds CC=gobot, golang-dev
https://golang.org/cl/9570043
parent
99f67228
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
21 deletions
+48
-21
src/pkg/net/http/serve_test.go
src/pkg/net/http/serve_test.go
+48
-21
No files found.
src/pkg/net/http/serve_test.go
View file @
950fa935
...
...
@@ -116,6 +116,12 @@ func (c *testConn) Close() error {
return
nil
}
// reqBytes treats req as a request (with \n delimiters) and returns it with \r\n delimiters,
// ending in \r\n\r\n
func
reqBytes
(
req
string
)
[]
byte
{
return
[]
byte
(
strings
.
Replace
(
strings
.
TrimSpace
(
req
),
"
\n
"
,
"
\r\n
"
,
-
1
)
+
"
\r\n\r\n
"
)
}
func
TestConsumingBodyOnNextConn
(
t
*
testing
.
T
)
{
conn
:=
new
(
testConn
)
for
i
:=
0
;
i
<
2
;
i
++
{
...
...
@@ -1408,10 +1414,7 @@ For:
func
TestCloseNotifierChanLeak
(
t
*
testing
.
T
)
{
defer
afterTest
(
t
)
req
:=
[]
byte
(
strings
.
Replace
(
`GET / HTTP/1.0
Host: golang.org
`
,
"
\n
"
,
"
\r\n
"
,
-
1
))
req
:=
reqBytes
(
"GET / HTTP/1.0
\n
Host: golang.org"
)
for
i
:=
0
;
i
<
20
;
i
++
{
var
output
bytes
.
Buffer
conn
:=
&
rwTestConn
{
...
...
@@ -1493,11 +1496,7 @@ func TestOptions(t *testing.T) {
// ones, even if the handler modifies them (~erroneously) after the
// first Write.
func
TestHeaderToWire
(
t
*
testing
.
T
)
{
req
:=
[]
byte
(
strings
.
Replace
(
`GET / HTTP/1.1
Host: golang.org
`
,
"
\n
"
,
"
\r\n
"
,
-
1
))
req
:=
reqBytes
(
"GET / HTTP/1.1
\n
Host: golang.org"
)
tests
:=
[]
struct
{
name
string
handler
func
(
ResponseWriter
,
*
Request
)
...
...
@@ -1726,6 +1725,38 @@ func TestAcceptMaxFds(t *testing.T) {
}
}
func
TestWriteAfterHijack
(
t
*
testing
.
T
)
{
req
:=
reqBytes
(
"GET / HTTP/1.1
\n
Host: golang.org"
)
var
buf
bytes
.
Buffer
wrotec
:=
make
(
chan
bool
,
1
)
conn
:=
&
rwTestConn
{
Reader
:
bytes
.
NewReader
(
req
),
Writer
:
&
buf
,
closec
:
make
(
chan
bool
,
1
),
}
handler
:=
HandlerFunc
(
func
(
rw
ResponseWriter
,
r
*
Request
)
{
conn
,
bufrw
,
err
:=
rw
.
(
Hijacker
)
.
Hijack
()
if
err
!=
nil
{
t
.
Error
(
err
)
return
}
go
func
()
{
bufrw
.
Write
([]
byte
(
"[hijack-to-bufw]"
))
bufrw
.
Flush
()
conn
.
Write
([]
byte
(
"[hijack-to-conn]"
))
conn
.
Close
()
wrotec
<-
true
}()
})
ln
:=
&
oneConnListener
{
conn
:
conn
}
go
Serve
(
ln
,
handler
)
<-
conn
.
closec
<-
wrotec
if
g
,
w
:=
buf
.
String
(),
"[hijack-to-bufw][hijack-to-conn]"
;
g
!=
w
{
t
.
Errorf
(
"wrote %q; want %q"
,
g
,
w
)
}
}
func
BenchmarkClientServer
(
b
*
testing
.
B
)
{
b
.
ReportAllocs
()
b
.
StopTimer
()
...
...
@@ -1854,15 +1885,14 @@ func BenchmarkServer(b *testing.B) {
func
BenchmarkServerFakeConnNoKeepAlive
(
b
*
testing
.
B
)
{
b
.
ReportAllocs
()
req
:=
[]
byte
(
strings
.
Replace
(
`GET / HTTP/1.0
req
:=
reqBytes
(
`GET / HTTP/1.0
Host: golang.org
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
`
,
"
\n
"
,
"
\r\n
"
,
-
1
))
`
)
res
:=
[]
byte
(
"Hello world!
\n
"
)
conn
:=
&
testConn
{
...
...
@@ -1908,15 +1938,14 @@ func (r *repeatReader) Read(p []byte) (n int, err error) {
func
BenchmarkServerFakeConnWithKeepAlive
(
b
*
testing
.
B
)
{
b
.
ReportAllocs
()
req
:=
[]
byte
(
strings
.
Replace
(
`GET / HTTP/1.1
req
:=
reqBytes
(
`GET / HTTP/1.1
Host: golang.org
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
`
,
"
\n
"
,
"
\r\n
"
,
-
1
))
`
)
res
:=
[]
byte
(
"Hello world!
\n
"
)
conn
:=
&
rwTestConn
{
...
...
@@ -1943,10 +1972,9 @@ Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
func
BenchmarkServerFakeConnWithKeepAliveLite
(
b
*
testing
.
B
)
{
b
.
ReportAllocs
()
req
:=
[]
byte
(
strings
.
Replace
(
`GET / HTTP/1.1
req
:=
reqBytes
(
`GET / HTTP/1.1
Host: golang.org
`
,
"
\n
"
,
"
\r\n
"
,
-
1
))
`
)
res
:=
[]
byte
(
"Hello world!
\n
"
)
conn
:=
&
rwTestConn
{
...
...
@@ -2006,10 +2034,9 @@ func BenchmarkServerHandlerNoHeader(b *testing.B) {
func
benchmarkHandler
(
b
*
testing
.
B
,
h
Handler
)
{
b
.
ReportAllocs
()
req
:=
[]
byte
(
strings
.
Replace
(
`GET / HTTP/1.1
req
:=
reqBytes
(
`GET / HTTP/1.1
Host: golang.org
`
,
"
\n
"
,
"
\r\n
"
,
-
1
))
`
)
conn
:=
&
rwTestConn
{
Reader
:
&
repeatReader
{
content
:
req
,
count
:
b
.
N
},
Writer
:
ioutil
.
Discard
,
...
...
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