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
4790dacb
Commit
4790dacb
authored
Jun 03, 2015
by
Viacheslav Biriukov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add without to proxy middleware
parent
4852f058
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
4 deletions
+16
-4
middleware/proxy/proxy.go
middleware/proxy/proxy.go
+2
-1
middleware/proxy/reverseproxy.go
middleware/proxy/reverseproxy.go
+6
-1
middleware/proxy/upstream.go
middleware/proxy/upstream.go
+8
-2
No files found.
middleware/proxy/proxy.go
View file @
4790dacb
...
@@ -42,6 +42,7 @@ type UpstreamHost struct {
...
@@ -42,6 +42,7 @@ type UpstreamHost struct {
Unhealthy
bool
Unhealthy
bool
ExtraHeaders
http
.
Header
ExtraHeaders
http
.
Header
CheckDown
UpstreamHostDownFunc
CheckDown
UpstreamHostDownFunc
Without
string
}
}
// Down checks whether the upstream host is down or not.
// Down checks whether the upstream host is down or not.
...
@@ -77,7 +78,7 @@ func (p Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
...
@@ -77,7 +78,7 @@ func (p Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
if
baseURL
,
err
:=
url
.
Parse
(
host
.
Name
);
err
==
nil
{
if
baseURL
,
err
:=
url
.
Parse
(
host
.
Name
);
err
==
nil
{
r
.
Host
=
baseURL
.
Host
r
.
Host
=
baseURL
.
Host
if
proxy
==
nil
{
if
proxy
==
nil
{
proxy
=
NewSingleHostReverseProxy
(
baseURL
)
proxy
=
NewSingleHostReverseProxy
(
baseURL
,
host
.
Without
)
}
}
}
else
if
proxy
==
nil
{
}
else
if
proxy
==
nil
{
return
http
.
StatusInternalServerError
,
err
return
http
.
StatusInternalServerError
,
err
...
...
middleware/proxy/reverseproxy.go
View file @
4790dacb
...
@@ -62,7 +62,9 @@ func singleJoiningSlash(a, b string) string {
...
@@ -62,7 +62,9 @@ func singleJoiningSlash(a, b string) string {
// URLs to the scheme, host, and base path provided in target. If the
// URLs to the scheme, host, and base path provided in target. If the
// target's path is "/base" and the incoming request was for "/dir",
// target's path is "/base" and the incoming request was for "/dir",
// the target request will be for /base/dir.
// the target request will be for /base/dir.
func
NewSingleHostReverseProxy
(
target
*
url
.
URL
)
*
ReverseProxy
{
// Without logic: target's path is "/", incoming is "/api/messages",
// without is "/api", then the target request will be for /messages.
func
NewSingleHostReverseProxy
(
target
*
url
.
URL
,
without
string
)
*
ReverseProxy
{
targetQuery
:=
target
.
RawQuery
targetQuery
:=
target
.
RawQuery
director
:=
func
(
req
*
http
.
Request
)
{
director
:=
func
(
req
*
http
.
Request
)
{
req
.
URL
.
Scheme
=
target
.
Scheme
req
.
URL
.
Scheme
=
target
.
Scheme
...
@@ -73,6 +75,9 @@ func NewSingleHostReverseProxy(target *url.URL) *ReverseProxy {
...
@@ -73,6 +75,9 @@ func NewSingleHostReverseProxy(target *url.URL) *ReverseProxy {
}
else
{
}
else
{
req
.
URL
.
RawQuery
=
targetQuery
+
"&"
+
req
.
URL
.
RawQuery
req
.
URL
.
RawQuery
=
targetQuery
+
"&"
+
req
.
URL
.
RawQuery
}
}
if
without
!=
""
{
req
.
URL
.
Path
=
strings
.
Replace
(
req
.
URL
.
Path
,
without
,
""
,
1
)
}
}
}
return
&
ReverseProxy
{
Director
:
director
}
return
&
ReverseProxy
{
Director
:
director
}
}
}
...
...
middleware/proxy/upstream.go
View file @
4790dacb
...
@@ -28,13 +28,13 @@ type staticUpstream struct {
...
@@ -28,13 +28,13 @@ type staticUpstream struct {
Path
string
Path
string
Interval
time
.
Duration
Interval
time
.
Duration
}
}
Without
string
}
}
// NewStaticUpstreams parses the configuration input and sets up
// NewStaticUpstreams parses the configuration input and sets up
// static upstreams for the proxy middleware.
// static upstreams for the proxy middleware.
func
NewStaticUpstreams
(
c
parse
.
Dispenser
)
([]
Upstream
,
error
)
{
func
NewStaticUpstreams
(
c
parse
.
Dispenser
)
([]
Upstream
,
error
)
{
var
upstreams
[]
Upstream
var
upstreams
[]
Upstream
for
c
.
Next
()
{
for
c
.
Next
()
{
upstream
:=
&
staticUpstream
{
upstream
:=
&
staticUpstream
{
from
:
""
,
from
:
""
,
...
@@ -104,6 +104,11 @@ func NewStaticUpstreams(c parse.Dispenser) ([]Upstream, error) {
...
@@ -104,6 +104,11 @@ func NewStaticUpstreams(c parse.Dispenser) ([]Upstream, error) {
case
"websocket"
:
case
"websocket"
:
proxyHeaders
.
Add
(
"Connection"
,
"{>Connection}"
)
proxyHeaders
.
Add
(
"Connection"
,
"{>Connection}"
)
proxyHeaders
.
Add
(
"Upgrade"
,
"{>Upgrade}"
)
proxyHeaders
.
Add
(
"Upgrade"
,
"{>Upgrade}"
)
case
"without"
:
if
!
c
.
NextArg
()
{
return
upstreams
,
c
.
ArgErr
()
}
upstream
.
Without
=
c
.
Val
()
}
}
}
}
...
@@ -131,9 +136,10 @@ func NewStaticUpstreams(c parse.Dispenser) ([]Upstream, error) {
...
@@ -131,9 +136,10 @@ func NewStaticUpstreams(c parse.Dispenser) ([]Upstream, error) {
return
false
return
false
}
}
}(
upstream
),
}(
upstream
),
Without
:
upstream
.
Without
,
}
}
if
baseURL
,
err
:=
url
.
Parse
(
uh
.
Name
);
err
==
nil
{
if
baseURL
,
err
:=
url
.
Parse
(
uh
.
Name
);
err
==
nil
{
uh
.
ReverseProxy
=
NewSingleHostReverseProxy
(
baseURL
)
uh
.
ReverseProxy
=
NewSingleHostReverseProxy
(
baseURL
,
uh
.
Without
)
}
else
{
}
else
{
return
upstreams
,
err
return
upstreams
,
err
}
}
...
...
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