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
b1e1caba
Commit
b1e1caba
authored
Apr 30, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: Graceful error handling during heavy load; proper error responses
parent
b51e8bc1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
3 deletions
+10
-3
server/fileserver.go
server/fileserver.go
+10
-3
No files found.
server/fileserver.go
View file @
b1e1caba
...
@@ -41,20 +41,27 @@ func (f *fileHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, er
...
@@ -41,20 +41,27 @@ func (f *fileHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, er
func
(
fh
*
fileHandler
)
serveFile
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
name
string
)
(
int
,
error
)
{
func
(
fh
*
fileHandler
)
serveFile
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
name
string
)
(
int
,
error
)
{
f
,
err
:=
fh
.
root
.
Open
(
name
)
f
,
err
:=
fh
.
root
.
Open
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
if
os
.
Is
Permission
(
err
)
{
if
os
.
Is
NotExist
(
err
)
{
return
http
.
StatusForbidden
,
err
return
http
.
StatusForbidden
,
err
}
}
else
if
os
.
IsPermission
(
err
)
{
return
http
.
StatusNotFound
,
nil
return
http
.
StatusNotFound
,
nil
}
}
// Likely the server is under load and ran out of file descriptors
w
.
Header
()
.
Set
(
"Retry-After"
,
"5"
)
// TODO: 5 seconds enough delay? Or too much?
return
http
.
StatusServiceUnavailable
,
err
}
defer
f
.
Close
()
defer
f
.
Close
()
d
,
err1
:=
f
.
Stat
()
d
,
err1
:=
f
.
Stat
()
if
err1
!=
nil
{
if
err1
!=
nil
{
if
os
.
IsPermission
(
err
)
{
if
os
.
IsPermission
(
err
)
{
return
http
.
StatusForbidden
,
err
return
http
.
StatusForbidden
,
err
}
}
else
if
os
.
IsNotExist
(
err
)
{
return
http
.
StatusNotFound
,
nil
return
http
.
StatusNotFound
,
nil
}
}
// Return a different status code than above so as to distinguish these cases
return
http
.
StatusInternalServerError
,
err
}
// redirect to canonical path
// redirect to canonical path
url
:=
r
.
URL
.
Path
url
:=
r
.
URL
.
Path
...
...
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