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
941318d3
Commit
941318d3
authored
Jan 07, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not show error pages in development mode
parent
165a1a4e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
5 deletions
+34
-5
error_pages.go
error_pages.go
+4
-1
error_pages_test.go
error_pages_test.go
+28
-2
main.go
main.go
+2
-2
No files found.
error_pages.go
View file @
941318d3
...
@@ -59,7 +59,10 @@ func (s *errorPageResponseWriter) Flush() {
...
@@ -59,7 +59,10 @@ func (s *errorPageResponseWriter) Flush() {
s
.
WriteHeader
(
http
.
StatusOK
)
s
.
WriteHeader
(
http
.
StatusOK
)
}
}
func
handleRailsError
(
documentRoot
*
string
,
handler
serviceHandleFunc
)
serviceHandleFunc
{
func
handleRailsError
(
documentRoot
*
string
,
enabled
*
bool
,
handler
serviceHandleFunc
)
serviceHandleFunc
{
if
!*
enabled
{
return
handler
}
return
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
return
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
rw
:=
errorPageResponseWriter
{
rw
:=
errorPageResponseWriter
{
rw
:
w
,
rw
:
w
,
...
...
error_pages_test.go
View file @
941318d3
...
@@ -22,7 +22,8 @@ func TestIfErrorPageIsPresented(t *testing.T) {
...
@@ -22,7 +22,8 @@ func TestIfErrorPageIsPresented(t *testing.T) {
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
handleRailsError
(
&
dir
,
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
enabled
:=
true
handleRailsError
(
&
dir
,
&
enabled
,
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
w
.
WriteHeader
(
404
)
w
.
WriteHeader
(
404
)
fmt
.
Fprint
(
w
,
"Not Found"
)
fmt
.
Fprint
(
w
,
"Not Found"
)
})(
w
,
nil
)
})(
w
,
nil
)
...
@@ -42,7 +43,8 @@ func TestIfErrorPassedIfNoErrorPageIsFound(t *testing.T) {
...
@@ -42,7 +43,8 @@ func TestIfErrorPassedIfNoErrorPageIsFound(t *testing.T) {
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
errorResponse
:=
"ERROR"
errorResponse
:=
"ERROR"
handleRailsError
(
&
dir
,
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
enabled
:=
true
handleRailsError
(
&
dir
,
&
enabled
,
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
w
.
WriteHeader
(
404
)
w
.
WriteHeader
(
404
)
fmt
.
Fprint
(
w
,
errorResponse
)
fmt
.
Fprint
(
w
,
errorResponse
)
})(
w
,
nil
)
})(
w
,
nil
)
...
@@ -51,3 +53,27 @@ func TestIfErrorPassedIfNoErrorPageIsFound(t *testing.T) {
...
@@ -51,3 +53,27 @@ func TestIfErrorPassedIfNoErrorPageIsFound(t *testing.T) {
assertResponseCode
(
t
,
w
,
404
)
assertResponseCode
(
t
,
w
,
404
)
assertResponseBody
(
t
,
w
,
errorResponse
)
assertResponseBody
(
t
,
w
,
errorResponse
)
}
}
func
TestIfErrorPageIsIgnoredInDevelopment
(
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
()
enabled
:=
false
serverError
:=
"Interesting Server Error"
handleRailsError
(
&
dir
,
&
enabled
,
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
w
.
WriteHeader
(
500
)
fmt
.
Fprint
(
w
,
serverError
)
})(
w
,
nil
)
w
.
Flush
()
assertResponseCode
(
t
,
w
,
500
)
assertResponseBody
(
t
,
w
,
serverError
)
}
main.go
View file @
941318d3
...
@@ -90,7 +90,7 @@ var httpRoutes = [...]httpRoute{
...
@@ -90,7 +90,7 @@ var httpRoutes = [...]httpRoute{
handleServeFile
(
documentRoot
,
CacheExpireMax
,
handleServeFile
(
documentRoot
,
CacheExpireMax
,
handleDevelopmentMode
(
developmentMode
,
handleDevelopmentMode
(
developmentMode
,
handleDeployPage
(
documentRoot
,
handleDeployPage
(
documentRoot
,
handleRailsError
(
documentRoot
,
handleRailsError
(
documentRoot
,
developmentMode
,
proxyRequest
,
proxyRequest
,
),
),
),
),
...
@@ -102,7 +102,7 @@ var httpRoutes = [...]httpRoute{
...
@@ -102,7 +102,7 @@ var httpRoutes = [...]httpRoute{
httpRoute
{
""
,
nil
,
httpRoute
{
""
,
nil
,
handleServeFile
(
documentRoot
,
CacheDisabled
,
handleServeFile
(
documentRoot
,
CacheDisabled
,
handleDeployPage
(
documentRoot
,
handleDeployPage
(
documentRoot
,
handleRailsError
(
documentRoot
,
handleRailsError
(
documentRoot
,
developmentMode
,
proxyRequest
,
proxyRequest
,
),
),
),
),
...
...
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