Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
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
Boxiang Sun
gitlab-ce
Commits
fea4efe4
Commit
fea4efe4
authored
Oct 01, 2018
by
David
Committed by
Stan Hu
Oct 01, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add custom header for error responses
parent
2176477d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
0 deletions
+91
-0
app/controllers/application_controller.rb
app/controllers/application_controller.rb
+9
-0
changelogs/unreleased/23197-add-custom-header-for-error-responses.yml
...nreleased/23197-add-custom-header-for-error-responses.yml
+6
-0
spec/controllers/application_controller_spec.rb
spec/controllers/application_controller_spec.rb
+76
-0
No files found.
app/controllers/application_controller.rb
View file @
fea4efe4
...
@@ -109,6 +109,15 @@ class ApplicationController < ActionController::Base
...
@@ -109,6 +109,15 @@ class ApplicationController < ActionController::Base
request
.
env
[
'rack.session.options'
][
:expire_after
]
=
Settings
.
gitlab
[
'unauthenticated_session_expire_delay'
]
request
.
env
[
'rack.session.options'
][
:expire_after
]
=
Settings
.
gitlab
[
'unauthenticated_session_expire_delay'
]
end
end
def
render
(
*
args
)
super
.
tap
do
# Set a header for custom error pages to prevent them from being intercepted by gitlab-workhorse
if
response
.
content_type
==
'text/html'
&&
(
400
..
599
).
cover?
(
response
.
status
)
response
.
headers
[
'X-GitLab-Custom-Error'
]
=
'1'
end
end
end
protected
protected
def
append_info_to_payload
(
payload
)
def
append_info_to_payload
(
payload
)
...
...
changelogs/unreleased/23197-add-custom-header-for-error-responses.yml
0 → 100644
View file @
fea4efe4
---
title
:
Set a header for custom error pages to prevent them from being intercepted
by gitlab-workhorse
merge_request
:
21870
author
:
David Piegza
type
:
fixed
spec/controllers/application_controller_spec.rb
View file @
fea4efe4
...
@@ -728,4 +728,80 @@ describe ApplicationController do
...
@@ -728,4 +728,80 @@ describe ApplicationController do
end
end
end
end
end
end
context
'X-GitLab-Custom-Error header'
do
before
do
sign_in
user
end
context
'given a 422 error page'
do
controller
do
def
index
render
'errors/omniauth_error'
,
layout:
'errors'
,
status:
422
end
end
it
'sets a custom header'
do
get
:index
expect
(
response
.
headers
[
'X-GitLab-Custom-Error'
]).
to
eq
'1'
end
end
context
'given a 500 error page'
do
controller
do
def
index
render
'errors/omniauth_error'
,
layout:
'errors'
,
status:
500
end
end
it
'sets a custom header'
do
get
:index
expect
(
response
.
headers
[
'X-GitLab-Custom-Error'
]).
to
eq
'1'
end
end
context
'given a 200 success page'
do
controller
do
def
index
render
'errors/omniauth_error'
,
layout:
'errors'
,
status:
200
end
end
it
'does not set a custom header'
do
get
:index
expect
(
response
.
headers
[
'X-GitLab-Custom-Error'
]).
to
be_nil
end
end
context
'given a json response'
do
controller
do
def
index
render
json:
{},
status: :unprocessable_entity
end
end
it
'does not set a custom header'
do
get
:index
,
format: :json
expect
(
response
.
headers
[
'X-GitLab-Custom-Error'
]).
to
be_nil
end
end
context
'given a json response for an html request'
do
controller
do
def
index
render
json:
{},
status: :unprocessable_entity
end
end
it
'does not set a custom header'
do
get
:index
expect
(
response
.
headers
[
'X-GitLab-Custom-Error'
]).
to
be_nil
end
end
end
end
end
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