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
59355765
Commit
59355765
authored
Jun 04, 2015
by
Viacheslav Biriukov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix tests and change naming
parent
4790dacb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
16 deletions
+22
-16
middleware/proxy/proxy.go
middleware/proxy/proxy.go
+10
-10
middleware/proxy/proxy_test.go
middleware/proxy/proxy_test.go
+7
-1
middleware/proxy/reverseproxy.go
middleware/proxy/reverseproxy.go
+1
-1
middleware/proxy/upstream.go
middleware/proxy/upstream.go
+4
-4
No files found.
middleware/proxy/proxy.go
View file @
59355765
...
...
@@ -34,15 +34,15 @@ type UpstreamHostDownFunc func(*UpstreamHost) bool
// UpstreamHost represents a single proxy upstream
type
UpstreamHost
struct
{
// The hostname of this upstream host
Name
string
ReverseProxy
*
ReverseProxy
Conns
int64
Fails
int32
FailTimeout
time
.
Duration
Unhealthy
bool
ExtraHeaders
http
.
Header
CheckDown
UpstreamHostDownFunc
Without
string
Name
string
ReverseProxy
*
ReverseProxy
Conns
int64
Fails
int32
FailTimeout
time
.
Duration
Unhealthy
bool
ExtraHeaders
http
.
Header
CheckDown
UpstreamHostDownFunc
Without
PathPrefix
string
}
// Down checks whether the upstream host is down or not.
...
...
@@ -78,7 +78,7 @@ func (p Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
if
baseURL
,
err
:=
url
.
Parse
(
host
.
Name
);
err
==
nil
{
r
.
Host
=
baseURL
.
Host
if
proxy
==
nil
{
proxy
=
NewSingleHostReverseProxy
(
baseURL
,
host
.
Without
)
proxy
=
NewSingleHostReverseProxy
(
baseURL
,
host
.
Without
PathPrefix
)
}
}
else
if
proxy
==
nil
{
return
http
.
StatusInternalServerError
,
err
...
...
middleware/proxy/proxy_test.go
View file @
59355765
...
...
@@ -120,7 +120,7 @@ func (u *fakeUpstream) Select() *UpstreamHost {
uri
,
_
:=
url
.
Parse
(
u
.
name
)
return
&
UpstreamHost
{
Name
:
u
.
name
,
ReverseProxy
:
NewSingleHostReverseProxy
(
uri
),
ReverseProxy
:
NewSingleHostReverseProxy
(
uri
,
""
),
ExtraHeaders
:
proxyHeaders
,
}
}
...
...
@@ -149,3 +149,9 @@ func (c *fakeConn) SetWriteDeadline(t time.Time) error { return nil }
func
(
c
*
fakeConn
)
Close
()
error
{
return
nil
}
func
(
c
*
fakeConn
)
Read
(
b
[]
byte
)
(
int
,
error
)
{
return
c
.
readBuf
.
Read
(
b
)
}
func
(
c
*
fakeConn
)
Write
(
b
[]
byte
)
(
int
,
error
)
{
return
c
.
writeBuf
.
Write
(
b
)
}
func
newWithoutPathPrefixTestProxy
(
backendAddr
string
)
*
Proxy
{
return
&
Proxy
{
Upstreams
:
[]
Upstream
{
&
fakeUpstreamWithoutPathPrefix
{
from
:
"/api/messages"
,
withoutPathPrefix
:
"/api"
}},
}
}
middleware/proxy/reverseproxy.go
View file @
59355765
...
...
@@ -76,7 +76,7 @@ func NewSingleHostReverseProxy(target *url.URL, without string) *ReverseProxy {
req
.
URL
.
RawQuery
=
targetQuery
+
"&"
+
req
.
URL
.
RawQuery
}
if
without
!=
""
{
req
.
URL
.
Path
=
strings
.
Replace
(
req
.
URL
.
Path
,
without
,
""
,
1
)
req
.
URL
.
Path
=
strings
.
TrimPrefix
(
req
.
URL
.
Path
,
without
)
}
}
return
&
ReverseProxy
{
Director
:
director
}
...
...
middleware/proxy/upstream.go
View file @
59355765
...
...
@@ -28,7 +28,7 @@ type staticUpstream struct {
Path
string
Interval
time
.
Duration
}
Without
string
Without
PathPrefix
string
}
// NewStaticUpstreams parses the configuration input and sets up
...
...
@@ -108,7 +108,7 @@ func NewStaticUpstreams(c parse.Dispenser) ([]Upstream, error) {
if
!
c
.
NextArg
()
{
return
upstreams
,
c
.
ArgErr
()
}
upstream
.
Without
=
c
.
Val
()
upstream
.
Without
PathPrefix
=
c
.
Val
()
}
}
...
...
@@ -136,10 +136,10 @@ func NewStaticUpstreams(c parse.Dispenser) ([]Upstream, error) {
return
false
}
}(
upstream
),
Without
:
upstream
.
Without
,
Without
PathPrefix
:
upstream
.
WithoutPathPrefix
,
}
if
baseURL
,
err
:=
url
.
Parse
(
uh
.
Name
);
err
==
nil
{
uh
.
ReverseProxy
=
NewSingleHostReverseProxy
(
baseURL
,
uh
.
Without
)
uh
.
ReverseProxy
=
NewSingleHostReverseProxy
(
baseURL
,
uh
.
Without
PathPrefix
)
}
else
{
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