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
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-ce
Commits
10b2383f
Commit
10b2383f
authored
Aug 14, 2019
by
George Koltsov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Exclude json content type from workhorse interception
parent
ab006779
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
11 deletions
+23
-11
app/controllers/application_controller.rb
app/controllers/application_controller.rb
+5
-1
spec/controllers/application_controller_spec.rb
spec/controllers/application_controller_spec.rb
+18
-10
No files found.
app/controllers/application_controller.rb
View file @
10b2383f
...
@@ -116,7 +116,7 @@ class ApplicationController < ActionController::Base
...
@@ -116,7 +116,7 @@ class ApplicationController < ActionController::Base
def
render
(
*
args
)
def
render
(
*
args
)
super
.
tap
do
super
.
tap
do
# Set a header for custom error pages to prevent them from being intercepted by gitlab-workhorse
# 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
)
if
workhorse_excluded_content_types
.
include?
(
response
.
content_type
)
&&
(
400
..
599
).
cover?
(
response
.
status
)
response
.
headers
[
'X-GitLab-Custom-Error'
]
=
'1'
response
.
headers
[
'X-GitLab-Custom-Error'
]
=
'1'
end
end
end
end
...
@@ -124,6 +124,10 @@ class ApplicationController < ActionController::Base
...
@@ -124,6 +124,10 @@ class ApplicationController < ActionController::Base
protected
protected
def
workhorse_excluded_content_types
@workhorse_excluded_content_types
||=
%w(text/html application/json)
end
def
append_info_to_payload
(
payload
)
def
append_info_to_payload
(
payload
)
super
super
...
...
spec/controllers/application_controller_spec.rb
View file @
10b2383f
...
@@ -641,24 +641,32 @@ describe ApplicationController do
...
@@ -641,24 +641,32 @@ describe ApplicationController do
end
end
end
end
it
'
does not set
a custom header'
do
it
'
sets
a custom header'
do
get
:index
,
format: :json
get
:index
,
format: :json
expect
(
response
.
headers
[
'X-GitLab-Custom-Error'
]).
to
be_nil
expect
(
response
.
headers
[
'X-GitLab-Custom-Error'
]).
to
eq
'1'
end
end
end
context
'given a json response for an html request'
do
context
'for html request'
do
controller
do
it
'sets a custom header'
do
def
index
get
:index
render
json:
{},
status: :unprocessable_entity
expect
(
response
.
headers
[
'X-GitLab-Custom-Error'
]).
to
eq
'1'
end
end
end
end
it
'does not set a custom header'
do
context
'for 200 response'
do
get
:index
controller
do
def
index
render
json:
{},
status: :ok
end
end
expect
(
response
.
headers
[
'X-GitLab-Custom-Error'
]).
to
be_nil
it
'does not set a custom header'
do
get
:index
,
format: :json
expect
(
response
.
headers
[
'X-GitLab-Custom-Error'
]).
to
be_nil
end
end
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