Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
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
nexedi
caddy
Commits
b63d9fdc
Commit
b63d9fdc
authored
Jul 25, 2017
by
Matt Holt
Committed by
GitHub
Jul 25, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1777 from tw4452852/chunked_ws
proxy: fix hang on chunked websocket server
parents
ae7e0982
9b073aad
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
1 deletion
+49
-1
caddyhttp/proxy/proxy_test.go
caddyhttp/proxy/proxy_test.go
+48
-0
caddyhttp/proxy/reverseproxy.go
caddyhttp/proxy/reverseproxy.go
+1
-1
No files found.
caddyhttp/proxy/proxy_test.go
View file @
b63d9fdc
...
...
@@ -1422,3 +1422,51 @@ func BenchmarkProxy(b *testing.B) {
p
.
ServeHTTP
(
w
,
r
)
}
}
func
TestChunkedWebSocketReverseProxy
(
t
*
testing
.
T
)
{
s
:=
websocket
.
Server
{
Handler
:
websocket
.
Handler
(
func
(
ws
*
websocket
.
Conn
)
{
for
{
select
{}
}
}),
}
s
.
Config
.
Header
=
http
.
Header
(
make
(
map
[
string
][]
string
))
s
.
Config
.
Header
.
Set
(
"Transfer-Encoding"
,
"chunked"
)
wsNop
:=
httptest
.
NewServer
(
s
)
defer
wsNop
.
Close
()
// Get proxy to use for the test
p
:=
newWebSocketTestProxy
(
wsNop
.
URL
,
false
)
// Create client request
r
:=
httptest
.
NewRequest
(
"GET"
,
"/"
,
nil
)
r
.
Header
=
http
.
Header
{
"Connection"
:
{
"Upgrade"
},
"Upgrade"
:
{
"websocket"
},
"Origin"
:
{
wsNop
.
URL
},
"Sec-WebSocket-Key"
:
{
"x3JJHMbDL1EzLkh9GBhXDw=="
},
"Sec-WebSocket-Version"
:
{
"13"
},
}
// Capture the request
w
:=
&
recorderHijacker
{
httptest
.
NewRecorder
(),
new
(
fakeConn
)}
// Booya! Do the test.
_
,
err
:=
p
.
ServeHTTP
(
w
,
r
)
// Make sure the backend accepted the WS connection.
// Mostly interested in the Upgrade and Connection response headers
// and the 101 status code.
expected
:=
[]
byte
(
"HTTP/1.1 101 Switching Protocols
\r\n
Upgrade: websocket
\r\n
Connection: Upgrade
\r\n
Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=
\r\n
Transfer-Encoding: chunked
\r\n\r\n
"
)
actual
:=
w
.
fakeConn
.
writeBuf
.
Bytes
()
if
!
bytes
.
Equal
(
actual
,
expected
)
{
t
.
Errorf
(
"Expected backend to accept response:
\n
'%s'
\n
Actually got:
\n
'%s'"
,
expected
,
actual
)
}
if
err
!=
nil
{
t
.
Error
(
err
)
}
}
caddyhttp/proxy/reverseproxy.go
View file @
b63d9fdc
...
...
@@ -272,7 +272,7 @@ func (rp *ReverseProxy) ServeHTTP(rw http.ResponseWriter, outreq *http.Request,
}
if
isWebsocket
{
res
.
Body
.
Close
()
defer
res
.
Body
.
Close
()
hj
,
ok
:=
rw
.
(
http
.
Hijacker
)
if
!
ok
{
panic
(
httpserver
.
NonHijackerError
{
Underlying
:
rw
})
...
...
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