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
Jérome Perrin
gitlab-ce
Commits
b612bcfc
Commit
b612bcfc
authored
Oct 23, 2017
by
Mike Greiling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement basic request inspector for use in Capybara tests
parent
04149dcc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
0 deletions
+60
-0
config/environments/test.rb
config/environments/test.rb
+1
-0
lib/gitlab/testing/request_inspector_middleware.rb
lib/gitlab/testing/request_inspector_middleware.rb
+59
-0
No files found.
config/environments/test.rb
View file @
b612bcfc
Rails
.
application
.
configure
do
Rails
.
application
.
configure
do
# Make sure the middleware is inserted first in middleware chain
# Make sure the middleware is inserted first in middleware chain
config
.
middleware
.
insert_before
(
'ActionDispatch::Static'
,
'Gitlab::Testing::RequestBlockerMiddleware'
)
config
.
middleware
.
insert_before
(
'ActionDispatch::Static'
,
'Gitlab::Testing::RequestBlockerMiddleware'
)
config
.
middleware
.
insert_before
(
'ActionDispatch::Static'
,
'Gitlab::Testing::RequestInspectorMiddleware'
)
# Settings specified here will take precedence over those in config/application.rb
# Settings specified here will take precedence over those in config/application.rb
...
...
lib/gitlab/testing/request_inspector_middleware.rb
0 → 100644
View file @
b612bcfc
module
Gitlab
module
Testing
class
RequestInspectorMiddleware
@@log_requests
=
Concurrent
::
AtomicBoolean
.
new
(
false
)
@@logged_requests
=
Concurrent
::
Array
.
new
# Resets the current request log and starts logging requests
def
self
.
log_requests!
@@logged_requests
.
replace
([])
@@log_requests
.
value
=
true
end
# Stops logging requests
def
self
.
stop_logging!
@@log_requests
.
value
=
false
end
def
self
.
requests
@@logged_requests
end
def
initialize
(
app
)
@app
=
app
end
def
call
(
env
)
return
@app
.
call
(
env
)
unless
@@log_requests
.
true?
url
=
env
[
'REQUEST_URI'
]
request_headers
=
env_http_headers
(
env
)
status
,
headers
,
body
=
@app
.
call
(
env
)
log_response
({
url:
url
,
status_code:
status
,
request_headers:
request_headers
,
response_headers:
headers
})
[
status
,
headers
,
body
]
end
private
def
env_http_headers
(
env
)
Hash
[
*
env
.
select
{
|
k
,
v
|
k
.
start_with?
'HTTP_'
}
.
collect
{
|
k
,
v
|
[
k
.
sub
(
/^HTTP_/
,
''
),
v
]}
.
collect
{
|
k
,
v
|
[
k
.
split
(
'_'
).
collect
(
&
:capitalize
).
join
(
'-'
),
v
]}
.
sort
.
flatten
]
end
def
log_response
(
response
)
@@logged_requests
.
push
(
response
)
STDOUT
.
puts
response
.
to_json
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