Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
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
1
Merge Requests
1
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
gitlab-workhorse
Commits
c18e7e1b
Commit
c18e7e1b
authored
Sep 26, 2018
by
Stan Hu
Committed by
Jacob Vosmaer
Sep 26, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support custom error page override via X-GitLab-Custom-Error
parent
a22e410e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
1 deletion
+68
-1
internal/staticpages/error_pages.go
internal/staticpages/error_pages.go
+3
-1
internal/staticpages/error_pages_test.go
internal/staticpages/error_pages_test.go
+65
-0
No files found.
internal/staticpages/error_pages.go
View file @
c18e7e1b
...
...
@@ -53,7 +53,9 @@ func (s *errorPageResponseWriter) WriteHeader(status int) {
s
.
status
=
status
if
400
<=
s
.
status
&&
s
.
status
<=
599
{
if
400
<=
s
.
status
&&
s
.
status
<=
599
&&
s
.
rw
.
Header
()
.
Get
(
"X-GitLab-Custom-Error"
)
==
""
&&
s
.
rw
.
Header
()
.
Get
(
"Content-Type"
)
!=
"application/json"
{
errorPageFile
:=
filepath
.
Join
(
s
.
path
,
fmt
.
Sprintf
(
"%d.html"
,
s
.
status
))
// check if custom error page exists, serve this page instead
...
...
internal/staticpages/error_pages_test.go
View file @
c18e7e1b
...
...
@@ -78,3 +78,68 @@ func TestIfErrorPageIsIgnoredInDevelopment(t *testing.T) {
testhelper
.
AssertResponseCode
(
t
,
w
,
500
)
testhelper
.
AssertResponseBody
(
t
,
w
,
serverError
)
}
func
TestIfErrorPageIsIgnoredIfCustomError
(
t
*
testing
.
T
)
{
dir
,
err
:=
ioutil
.
TempDir
(
""
,
"error_page"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
os
.
RemoveAll
(
dir
)
errorPage
:=
"ERROR"
ioutil
.
WriteFile
(
filepath
.
Join
(
dir
,
"500.html"
),
[]
byte
(
errorPage
),
0600
)
w
:=
httptest
.
NewRecorder
()
serverError
:=
"Interesting Server Error"
h
:=
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
w
.
Header
()
.
Add
(
"X-GitLab-Custom-Error"
,
"1"
)
w
.
WriteHeader
(
500
)
fmt
.
Fprint
(
w
,
serverError
)
})
st
:=
&
Static
{
dir
}
st
.
ErrorPagesUnless
(
false
,
h
)
.
ServeHTTP
(
w
,
nil
)
w
.
Flush
()
testhelper
.
AssertResponseCode
(
t
,
w
,
500
)
testhelper
.
AssertResponseBody
(
t
,
w
,
serverError
)
}
func
TestErrorPageInterceptedByContentType
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
contentType
string
intercepted
bool
}{
{
contentType
:
"application/json"
,
intercepted
:
false
},
{
contentType
:
"text/plain"
,
intercepted
:
true
},
{
contentType
:
"text/html"
,
intercepted
:
true
},
{
contentType
:
""
,
intercepted
:
true
},
}
for
_
,
tc
:=
range
testCases
{
dir
,
err
:=
ioutil
.
TempDir
(
""
,
"error_page"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
os
.
RemoveAll
(
dir
)
errorPage
:=
"ERROR"
ioutil
.
WriteFile
(
filepath
.
Join
(
dir
,
"500.html"
),
[]
byte
(
errorPage
),
0600
)
w
:=
httptest
.
NewRecorder
()
serverError
:=
"Interesting Server Error"
h
:=
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
w
.
Header
()
.
Add
(
"Content-Type"
,
tc
.
contentType
)
w
.
WriteHeader
(
500
)
fmt
.
Fprint
(
w
,
serverError
)
})
st
:=
&
Static
{
dir
}
st
.
ErrorPagesUnless
(
false
,
h
)
.
ServeHTTP
(
w
,
nil
)
w
.
Flush
()
testhelper
.
AssertResponseCode
(
t
,
w
,
500
)
if
tc
.
intercepted
{
testhelper
.
AssertResponseBody
(
t
,
w
,
errorPage
)
}
else
{
testhelper
.
AssertResponseBody
(
t
,
w
,
serverError
)
}
}
}
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