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
e3d64169
Commit
e3d64169
authored
May 07, 2015
by
Michael Schoebel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adapted internal middleware
- Detect too many internal redirects - return 500 in this case
parent
a5b565e1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
2 deletions
+11
-2
middleware/internal/internal.go
middleware/internal/internal.go
+11
-2
No files found.
middleware/internal/internal.go
View file @
e3d64169
...
...
@@ -16,7 +16,10 @@ type Internal struct {
Paths
[]
string
}
const
redirectHeader
string
=
"X-Accel-Redirect"
const
(
redirectHeader
string
=
"X-Accel-Redirect"
maxRedirectCount
int
=
10
)
func
isInternalRedirect
(
w
http
.
ResponseWriter
)
bool
{
return
w
.
Header
()
.
Get
(
redirectHeader
)
!=
""
...
...
@@ -37,7 +40,7 @@ func (i Internal) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)
iw
:=
internalResponseWriter
{
ResponseWriter
:
w
}
status
,
err
:=
i
.
Next
.
ServeHTTP
(
iw
,
r
)
for
isInternalRedirect
(
iw
)
{
for
c
:=
0
;
c
<
maxRedirectCount
&&
isInternalRedirect
(
iw
);
c
++
{
// Redirect - adapt request URL path and send it again
// "down the chain"
r
.
URL
.
Path
=
iw
.
Header
()
.
Get
(
redirectHeader
)
...
...
@@ -46,6 +49,12 @@ func (i Internal) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)
status
,
err
=
i
.
Next
.
ServeHTTP
(
iw
,
r
)
}
if
isInternalRedirect
(
iw
)
{
// Too many redirect cycles
iw
.
ClearHeader
()
return
http
.
StatusInternalServerError
,
nil
}
return
status
,
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