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
Łukasz Nowak
caddy
Commits
5ddcd603
Commit
5ddcd603
authored
Jun 01, 2015
by
Matt Holt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #96 from acmacalister/feature/ws-proxy
add supported for ws in reverse proxy
parents
9bdd9bde
68cd4bde
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
12 deletions
+45
-12
config/setup/rewrite_test.go
config/setup/rewrite_test.go
+2
-1
middleware/proxy/reverseproxy.go
middleware/proxy/reverseproxy.go
+35
-6
middleware/proxy/upstream.go
middleware/proxy/upstream.go
+8
-5
No files found.
config/setup/rewrite_test.go
View file @
5ddcd603
...
@@ -4,8 +4,9 @@ import (
...
@@ -4,8 +4,9 @@ import (
"testing"
"testing"
"fmt"
"fmt"
"github.com/mholt/caddy/middleware/rewrite"
"regexp"
"regexp"
"github.com/mholt/caddy/middleware/rewrite"
)
)
func
TestRewrite
(
t
*
testing
.
T
)
{
func
TestRewrite
(
t
*
testing
.
T
)
{
...
...
middleware/proxy/reverseproxy.go
View file @
5ddcd603
...
@@ -147,6 +147,33 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request, extr
...
@@ -147,6 +147,33 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request, extr
}
}
defer
res
.
Body
.
Close
()
defer
res
.
Body
.
Close
()
if
res
.
StatusCode
==
http
.
StatusSwitchingProtocols
&&
res
.
Header
.
Get
(
"Upgrade"
)
==
"websocket"
{
hj
,
ok
:=
rw
.
(
http
.
Hijacker
)
if
!
ok
{
return
nil
}
conn
,
_
,
err
:=
hj
.
Hijack
()
if
err
!=
nil
{
return
err
}
backendConn
,
err
:=
net
.
Dial
(
"tcp"
,
outreq
.
Host
)
if
err
!=
nil
{
conn
.
Close
()
return
err
}
outreq
.
Write
(
backendConn
)
go
func
()
{
io
.
Copy
(
backendConn
,
conn
)
// write tcp stream to backend.
backendConn
.
Close
()
}()
io
.
Copy
(
conn
,
backendConn
)
// read tcp stream from backend.
conn
.
Close
()
}
else
{
for
_
,
h
:=
range
hopHeaders
{
for
_
,
h
:=
range
hopHeaders
{
res
.
Header
.
Del
(
h
)
res
.
Header
.
Del
(
h
)
}
}
...
@@ -155,6 +182,8 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request, extr
...
@@ -155,6 +182,8 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request, extr
rw
.
WriteHeader
(
res
.
StatusCode
)
rw
.
WriteHeader
(
res
.
StatusCode
)
p
.
copyResponse
(
rw
,
res
.
Body
)
p
.
copyResponse
(
rw
,
res
.
Body
)
}
return
nil
return
nil
}
}
...
...
middleware/proxy/upstream.go
View file @
5ddcd603
...
@@ -12,7 +12,10 @@ import (
...
@@ -12,7 +12,10 @@ import (
"github.com/mholt/caddy/config/parse"
"github.com/mholt/caddy/config/parse"
)
)
var
supportedPolicies
map
[
string
]
func
()
Policy
=
make
(
map
[
string
]
func
()
Policy
)
var
(
supportedPolicies
map
[
string
]
func
()
Policy
=
make
(
map
[
string
]
func
()
Policy
)
proxyHeaders
http
.
Header
=
make
(
http
.
Header
)
)
type
staticUpstream
struct
{
type
staticUpstream
struct
{
from
string
from
string
...
@@ -40,7 +43,7 @@ func NewStaticUpstreams(c parse.Dispenser) ([]Upstream, error) {
...
@@ -40,7 +43,7 @@ func NewStaticUpstreams(c parse.Dispenser) ([]Upstream, error) {
FailTimeout
:
10
*
time
.
Second
,
FailTimeout
:
10
*
time
.
Second
,
MaxFails
:
1
,
MaxFails
:
1
,
}
}
var
proxyHeaders
http
.
Header
if
!
c
.
Args
(
&
upstream
.
from
)
{
if
!
c
.
Args
(
&
upstream
.
from
)
{
return
upstreams
,
c
.
ArgErr
()
return
upstreams
,
c
.
ArgErr
()
}
}
...
@@ -97,10 +100,10 @@ func NewStaticUpstreams(c parse.Dispenser) ([]Upstream, error) {
...
@@ -97,10 +100,10 @@ func NewStaticUpstreams(c parse.Dispenser) ([]Upstream, error) {
if
!
c
.
Args
(
&
header
,
&
value
)
{
if
!
c
.
Args
(
&
header
,
&
value
)
{
return
upstreams
,
c
.
ArgErr
()
return
upstreams
,
c
.
ArgErr
()
}
}
if
proxyHeaders
==
nil
{
proxyHeaders
=
make
(
map
[
string
][]
string
)
}
proxyHeaders
.
Add
(
header
,
value
)
proxyHeaders
.
Add
(
header
,
value
)
case
"websocket"
:
proxyHeaders
.
Add
(
"Connection"
,
"{>Connection}"
)
proxyHeaders
.
Add
(
"Upgrade"
,
"{>Upgrade}"
)
}
}
}
}
...
...
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