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
280ba9db
Commit
280ba9db
authored
Nov 17, 2015
by
Matt Holt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #345 from tw4452852/my_proxy
proxy: make http header block scoped
parents
7f98a6cc
f56d2090
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
14 deletions
+17
-14
middleware/proxy/proxy_test.go
middleware/proxy/proxy_test.go
+3
-6
middleware/proxy/upstream.go
middleware/proxy/upstream.go
+14
-8
No files found.
middleware/proxy/proxy_test.go
View file @
280ba9db
...
@@ -98,11 +98,6 @@ func TestWebSocketReverseProxyFromWSClient(t *testing.T) {
...
@@ -98,11 +98,6 @@ func TestWebSocketReverseProxyFromWSClient(t *testing.T) {
// also sets up the rules/environment for testing WebSocket
// also sets up the rules/environment for testing WebSocket
// proxy.
// proxy.
func
newWebSocketTestProxy
(
backendAddr
string
)
*
Proxy
{
func
newWebSocketTestProxy
(
backendAddr
string
)
*
Proxy
{
proxyHeaders
=
http
.
Header
{
"Connection"
:
{
"{>Connection}"
},
"Upgrade"
:
{
"{>Upgrade}"
},
}
return
&
Proxy
{
return
&
Proxy
{
Upstreams
:
[]
Upstream
{
&
fakeUpstream
{
name
:
backendAddr
}},
Upstreams
:
[]
Upstream
{
&
fakeUpstream
{
name
:
backendAddr
}},
}
}
...
@@ -121,7 +116,9 @@ func (u *fakeUpstream) Select() *UpstreamHost {
...
@@ -121,7 +116,9 @@ func (u *fakeUpstream) Select() *UpstreamHost {
return
&
UpstreamHost
{
return
&
UpstreamHost
{
Name
:
u
.
name
,
Name
:
u
.
name
,
ReverseProxy
:
NewSingleHostReverseProxy
(
uri
,
""
),
ReverseProxy
:
NewSingleHostReverseProxy
(
uri
,
""
),
ExtraHeaders
:
proxyHeaders
,
ExtraHeaders
:
http
.
Header
{
"Connection"
:
{
"{>Connection}"
},
"Upgrade"
:
{
"{>Upgrade}"
}},
}
}
}
}
...
...
middleware/proxy/upstream.go
View file @
280ba9db
...
@@ -16,13 +16,13 @@ import (
...
@@ -16,13 +16,13 @@ import (
var
(
var
(
supportedPolicies
=
make
(
map
[
string
]
func
()
Policy
)
supportedPolicies
=
make
(
map
[
string
]
func
()
Policy
)
proxyHeaders
=
make
(
http
.
Header
)
)
)
type
staticUpstream
struct
{
type
staticUpstream
struct
{
from
string
from
string
Hosts
HostPool
proxyHeaders
http
.
Header
Policy
Policy
Hosts
HostPool
Policy
Policy
FailTimeout
time
.
Duration
FailTimeout
time
.
Duration
MaxFails
int32
MaxFails
int32
...
@@ -72,7 +72,7 @@ func NewStaticUpstreams(c parse.Dispenser) ([]Upstream, error) {
...
@@ -72,7 +72,7 @@ func NewStaticUpstreams(c parse.Dispenser) ([]Upstream, error) {
Fails
:
0
,
Fails
:
0
,
FailTimeout
:
upstream
.
FailTimeout
,
FailTimeout
:
upstream
.
FailTimeout
,
Unhealthy
:
false
,
Unhealthy
:
false
,
ExtraHeaders
:
proxyHeaders
,
ExtraHeaders
:
upstream
.
proxyHeaders
,
CheckDown
:
func
(
upstream
*
staticUpstream
)
UpstreamHostDownFunc
{
CheckDown
:
func
(
upstream
*
staticUpstream
)
UpstreamHostDownFunc
{
return
func
(
uh
*
UpstreamHost
)
bool
{
return
func
(
uh
*
UpstreamHost
)
bool
{
if
uh
.
Unhealthy
{
if
uh
.
Unhealthy
{
...
@@ -159,10 +159,16 @@ func parseBlock(c *parse.Dispenser, u *staticUpstream) error {
...
@@ -159,10 +159,16 @@ func parseBlock(c *parse.Dispenser, u *staticUpstream) error {
if
!
c
.
Args
(
&
header
,
&
value
)
{
if
!
c
.
Args
(
&
header
,
&
value
)
{
return
c
.
ArgErr
()
return
c
.
ArgErr
()
}
}
proxyHeaders
.
Add
(
header
,
value
)
if
u
.
proxyHeaders
==
nil
{
u
.
proxyHeaders
=
make
(
http
.
Header
)
}
u
.
proxyHeaders
.
Add
(
header
,
value
)
case
"websocket"
:
case
"websocket"
:
proxyHeaders
.
Add
(
"Connection"
,
"{>Connection}"
)
if
u
.
proxyHeaders
==
nil
{
proxyHeaders
.
Add
(
"Upgrade"
,
"{>Upgrade}"
)
u
.
proxyHeaders
=
make
(
http
.
Header
)
}
u
.
proxyHeaders
.
Add
(
"Connection"
,
"{>Connection}"
)
u
.
proxyHeaders
.
Add
(
"Upgrade"
,
"{>Upgrade}"
)
case
"without"
:
case
"without"
:
if
!
c
.
NextArg
()
{
if
!
c
.
NextArg
()
{
return
c
.
ArgErr
()
return
c
.
ArgErr
()
...
...
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