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
9b9a77a1
Commit
9b9a77a1
authored
Sep 24, 2016
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
proxy: Improved error reporting
We now report the actual error message rather than a generic one
parent
9077cce1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
5 deletions
+7
-5
caddyhttp/proxy/proxy.go
caddyhttp/proxy/proxy.go
+7
-5
No files found.
caddyhttp/proxy/proxy.go
View file @
9b9a77a1
...
@@ -13,8 +13,6 @@ import (
...
@@ -13,8 +13,6 @@ import (
"github.com/mholt/caddy/caddyhttp/httpserver"
"github.com/mholt/caddy/caddyhttp/httpserver"
)
)
var
errUnreachable
=
errors
.
New
(
"unreachable backend"
)
// Proxy represents a middleware instance that can proxy requests.
// Proxy represents a middleware instance that can proxy requests.
type
Proxy
struct
{
type
Proxy
struct
{
Next
httpserver
.
Handler
Next
httpserver
.
Handler
...
@@ -92,10 +90,14 @@ func (p Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
...
@@ -92,10 +90,14 @@ func (p Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
// since Select() should give us "up" hosts, keep retrying
// since Select() should give us "up" hosts, keep retrying
// hosts until timeout (or until we get a nil host).
// hosts until timeout (or until we get a nil host).
start
:=
time
.
Now
()
start
:=
time
.
Now
()
var
backendErr
error
for
time
.
Now
()
.
Sub
(
start
)
<
tryDuration
{
for
time
.
Now
()
.
Sub
(
start
)
<
tryDuration
{
host
:=
upstream
.
Select
(
r
)
host
:=
upstream
.
Select
(
r
)
if
host
==
nil
{
if
host
==
nil
{
return
http
.
StatusBadGateway
,
errUnreachable
if
backendErr
==
nil
{
backendErr
=
errors
.
New
(
"no hosts available upstream"
)
}
return
http
.
StatusBadGateway
,
backendErr
}
}
if
rr
,
ok
:=
w
.
(
*
httpserver
.
ResponseRecorder
);
ok
&&
rr
.
Replacer
!=
nil
{
if
rr
,
ok
:=
w
.
(
*
httpserver
.
ResponseRecorder
);
ok
&&
rr
.
Replacer
!=
nil
{
rr
.
Replacer
.
Set
(
"upstream"
,
host
.
Name
)
rr
.
Replacer
.
Set
(
"upstream"
,
host
.
Name
)
...
@@ -141,7 +143,7 @@ func (p Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
...
@@ -141,7 +143,7 @@ func (p Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
// tell the proxy to serve the request
// tell the proxy to serve the request
atomic
.
AddInt64
(
&
host
.
Conns
,
1
)
atomic
.
AddInt64
(
&
host
.
Conns
,
1
)
backendErr
:
=
proxy
.
ServeHTTP
(
w
,
outreq
,
downHeaderUpdateFn
)
backendErr
=
proxy
.
ServeHTTP
(
w
,
outreq
,
downHeaderUpdateFn
)
atomic
.
AddInt64
(
&
host
.
Conns
,
-
1
)
atomic
.
AddInt64
(
&
host
.
Conns
,
-
1
)
// if no errors, we're done here; otherwise failover
// if no errors, we're done here; otherwise failover
...
@@ -159,7 +161,7 @@ func (p Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
...
@@ -159,7 +161,7 @@ func (p Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
}(
host
,
timeout
)
}(
host
,
timeout
)
}
}
return
http
.
StatusBadGateway
,
errUnreachable
return
http
.
StatusBadGateway
,
backendErr
}
}
// match finds the best match for a proxy config based
// match finds the best match for a proxy config based
...
...
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