Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
59e6272b
Commit
59e6272b
authored
May 26, 2015
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
integration: Add WebSocket upgrade test
parent
323fc8c5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
1 deletion
+65
-1
README.rst
README.rst
+1
-0
integration-tests/Makefile.am
integration-tests/Makefile.am
+1
-0
integration-tests/nghttpx_http1_test.go
integration-tests/nghttpx_http1_test.go
+22
-0
integration-tests/server_tester.go
integration-tests/server_tester.go
+41
-1
No files found.
README.rst
View file @
59e6272b
...
@@ -191,6 +191,7 @@ its testing framework. We depend on the following libraries:
...
@@ -191,6 +191,7 @@ its testing framework. We depend on the following libraries:
* https://github.com/bradfitz/http2
* https://github.com/bradfitz/http2
* https://github.com/tatsuhiro-t/go-nghttp2
* https://github.com/tatsuhiro-t/go-nghttp2
* https://github.com/tatsuhiro-t/spdy
* https://github.com/tatsuhiro-t/spdy
* golang.org/x/net/websocket
To download the above packages, after settings ``GOPATH``, run the
To download the above packages, after settings ``GOPATH``, run the
following command under ``integration-tests`` directory::
following command under ``integration-tests`` directory::
...
...
integration-tests/Makefile.am
View file @
59e6272b
...
@@ -38,6 +38,7 @@ itprep:
...
@@ -38,6 +38,7 @@ itprep:
go get
-d
-v
github.com/bradfitz/http2
go get
-d
-v
github.com/bradfitz/http2
go get
-d
-v
github.com/tatsuhiro-t/go-nghttp2
go get
-d
-v
github.com/tatsuhiro-t/go-nghttp2
go get
-d
-v
github.com/tatsuhiro-t/spdy
go get
-d
-v
github.com/tatsuhiro-t/spdy
go get
-d
-v
golang.org/x/net/websocket
it
:
it
:
sh setenv go
test
-v
sh setenv go
test
-v
integration-tests/nghttpx_http1_test.go
View file @
59e6272b
...
@@ -2,8 +2,10 @@ package nghttp2
...
@@ -2,8 +2,10 @@ package nghttp2
import
(
import
(
"bufio"
"bufio"
"bytes"
"fmt"
"fmt"
"github.com/bradfitz/http2/hpack"
"github.com/bradfitz/http2/hpack"
"golang.org/x/net/websocket"
"io"
"io"
"net/http"
"net/http"
"syscall"
"syscall"
...
@@ -312,6 +314,26 @@ func TestH1H1HeaderFields(t *testing.T) {
...
@@ -312,6 +314,26 @@ func TestH1H1HeaderFields(t *testing.T) {
}
}
}
}
// TestH1H1Websocket tests that HTTP Upgrade to WebSocket works.
func
TestH1H1Websocket
(
t
*
testing
.
T
)
{
st
:=
newServerTesterHandler
(
nil
,
t
,
websocket
.
Handler
(
func
(
ws
*
websocket
.
Conn
)
{
io
.
Copy
(
ws
,
ws
)
}))
defer
st
.
Close
()
content
:=
[]
byte
(
"hello world"
)
res
,
err
:=
st
.
websocket
(
requestParam
{
name
:
"TestH1H1Websocket"
,
body
:
content
,
})
if
err
!=
nil
{
t
.
Fatalf
(
"Error st.websocket() = %v"
,
err
)
}
if
got
,
want
:=
res
.
body
,
content
;
!
bytes
.
Equal
(
got
,
want
)
{
t
.
Errorf
(
"echo: %q; want %q"
,
got
,
want
)
}
}
// TestH1H2ConnectFailure tests that server handles the situation that
// TestH1H2ConnectFailure tests that server handles the situation that
// connection attempt to HTTP/2 backend failed.
// connection attempt to HTTP/2 backend failed.
func
TestH1H2ConnectFailure
(
t
*
testing
.
T
)
{
func
TestH1H2ConnectFailure
(
t
*
testing
.
T
)
{
...
...
integration-tests/server_tester.go
View file @
59e6272b
...
@@ -10,6 +10,7 @@ import (
...
@@ -10,6 +10,7 @@ import (
"github.com/bradfitz/http2/hpack"
"github.com/bradfitz/http2/hpack"
"github.com/tatsuhiro-t/go-nghttp2"
"github.com/tatsuhiro-t/go-nghttp2"
"github.com/tatsuhiro-t/spdy"
"github.com/tatsuhiro-t/spdy"
"golang.org/x/net/websocket"
"io"
"io"
"io/ioutil"
"io/ioutil"
"net"
"net"
...
@@ -66,6 +67,10 @@ func newServerTester(args []string, t *testing.T, handler http.HandlerFunc) *ser
...
@@ -66,6 +67,10 @@ func newServerTester(args []string, t *testing.T, handler http.HandlerFunc) *ser
return
newServerTesterInternal
(
args
,
t
,
handler
,
false
,
nil
)
return
newServerTesterInternal
(
args
,
t
,
handler
,
false
,
nil
)
}
}
func
newServerTesterHandler
(
args
[]
string
,
t
*
testing
.
T
,
handler
http
.
Handler
)
*
serverTester
{
return
newServerTesterInternal
(
args
,
t
,
handler
,
false
,
nil
)
}
// newServerTester creates test context for TLS frontend connection.
// newServerTester creates test context for TLS frontend connection.
func
newServerTesterTLS
(
args
[]
string
,
t
*
testing
.
T
,
handler
http
.
HandlerFunc
)
*
serverTester
{
func
newServerTesterTLS
(
args
[]
string
,
t
*
testing
.
T
,
handler
http
.
HandlerFunc
)
*
serverTester
{
return
newServerTesterInternal
(
args
,
t
,
handler
,
true
,
nil
)
return
newServerTesterInternal
(
args
,
t
,
handler
,
true
,
nil
)
...
@@ -79,7 +84,7 @@ func newServerTesterTLSConfig(args []string, t *testing.T, handler http.HandlerF
...
@@ -79,7 +84,7 @@ func newServerTesterTLSConfig(args []string, t *testing.T, handler http.HandlerF
// newServerTesterInternal creates test context. If frontendTLS is
// newServerTesterInternal creates test context. If frontendTLS is
// true, set up TLS frontend connection.
// true, set up TLS frontend connection.
func
newServerTesterInternal
(
args
[]
string
,
t
*
testing
.
T
,
handler
http
.
Handler
Func
,
frontendTLS
bool
,
clientConfig
*
tls
.
Config
)
*
serverTester
{
func
newServerTesterInternal
(
args
[]
string
,
t
*
testing
.
T
,
handler
http
.
Handler
,
frontendTLS
bool
,
clientConfig
*
tls
.
Config
)
*
serverTester
{
ts
:=
httptest
.
NewUnstartedServer
(
handler
)
ts
:=
httptest
.
NewUnstartedServer
(
handler
)
backendTLS
:=
false
backendTLS
:=
false
...
@@ -279,6 +284,41 @@ func (cbr *chunkedBodyReader) Read(p []byte) (n int, err error) {
...
@@ -279,6 +284,41 @@ func (cbr *chunkedBodyReader) Read(p []byte) (n int, err error) {
return
cbr
.
body
.
Read
(
p
)
return
cbr
.
body
.
Read
(
p
)
}
}
func
(
st
*
serverTester
)
websocket
(
rp
requestParam
)
(
*
serverResponse
,
error
)
{
urlstring
:=
st
.
url
+
"/echo"
config
,
err
:=
websocket
.
NewConfig
(
urlstring
,
st
.
url
)
if
err
!=
nil
{
st
.
t
.
Fatalf
(
"websocket.NewConfig(%q, %q) returned error: %v"
,
urlstring
,
st
.
url
,
err
)
}
config
.
Header
.
Add
(
"Test-Case"
,
rp
.
name
)
for
_
,
h
:=
range
rp
.
header
{
config
.
Header
.
Add
(
h
.
Name
,
h
.
Value
)
}
ws
,
err
:=
websocket
.
NewClient
(
config
,
st
.
conn
)
if
err
!=
nil
{
st
.
t
.
Fatalf
(
"Error creating websocket client: %v"
,
err
)
}
if
_
,
err
:=
ws
.
Write
(
rp
.
body
);
err
!=
nil
{
st
.
t
.
Fatalf
(
"ws.Write() returned error: %v"
,
err
)
}
msg
:=
make
([]
byte
,
1024
)
var
n
int
if
n
,
err
=
ws
.
Read
(
msg
);
err
!=
nil
{
st
.
t
.
Fatalf
(
"ws.Read() returned error: %v"
,
err
)
}
res
:=
&
serverResponse
{
body
:
msg
[
:
n
],
}
return
res
,
nil
}
func
(
st
*
serverTester
)
http1
(
rp
requestParam
)
(
*
serverResponse
,
error
)
{
func
(
st
*
serverTester
)
http1
(
rp
requestParam
)
(
*
serverResponse
,
error
)
{
method
:=
"GET"
method
:=
"GET"
if
rp
.
method
!=
""
{
if
rp
.
method
!=
""
{
...
...
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