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
8662789a
Commit
8662789a
authored
Dec 16, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Limit API failure response buffer size
parent
5f36b358
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
5 deletions
+23
-5
internal/api/api.go
internal/api/api.go
+23
-5
No files found.
internal/api/api.go
View file @
8662789a
...
...
@@ -18,10 +18,15 @@ import (
"gitlab.com/gitlab-org/gitlab-workhorse/internal/secret"
)
// Custom content type for API responses, to catch routing / programming mistakes
const
ResponseContentType
=
"application/vnd.gitlab-workhorse+json"
const
(
// Custom content type for API responses, to catch routing / programming mistakes
ResponseContentType
=
"application/vnd.gitlab-workhorse+json"
const
RequestHeader
=
"Gitlab-Workhorse-Api-Request"
// This header carries the JWT token for gitlab-rails
RequestHeader
=
"Gitlab-Workhorse-Api-Request"
failureResponseLimit
=
32768
)
type
API
struct
{
Client
*
http
.
Client
...
...
@@ -224,8 +229,7 @@ func (api *API) PreAuthorizeHandler(next HandleFunc, suffix string) http.Handler
// X-Accel-Buffering: no) but we still want to free up the Unicorn worker
// that generated httpResponse as fast as possible. To do this we buffer
// the entire response body in memory before sending it on.
responseBody
:=
&
bytes
.
Buffer
{}
_
,
err
:=
io
.
Copy
(
responseBody
,
httpResponse
.
Body
)
responseBody
,
err
:=
bufferResponse
(
httpResponse
.
Body
)
if
err
!=
nil
{
helper
.
Fail500
(
w
,
r
,
err
)
}
...
...
@@ -262,3 +266,17 @@ func (api *API) PreAuthorizeHandler(next HandleFunc, suffix string) http.Handler
next
(
w
,
r
,
authResponse
)
})
}
func
bufferResponse
(
r
io
.
Reader
)
(
*
bytes
.
Buffer
,
error
)
{
responseBody
:=
&
bytes
.
Buffer
{}
n
,
err
:=
io
.
Copy
(
responseBody
,
io
.
LimitReader
(
r
,
failureResponseLimit
))
if
err
!=
nil
{
return
nil
,
err
}
if
n
==
failureResponseLimit
{
return
nil
,
fmt
.
Errorf
(
"response body exceeded maximum buffer size (%d bytes)"
,
failureResponseLimit
)
}
return
responseBody
,
nil
}
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