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
20ee508c
Commit
20ee508c
authored
Dec 16, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Buffer API failure responses in memory
parent
5aa350e3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
5 deletions
+20
-5
internal/api/api.go
internal/api/api.go
+20
-5
No files found.
internal/api/api.go
View file @
20ee508c
package
api
import
(
"bytes"
"encoding/json"
"fmt"
"io"
...
...
@@ -187,8 +188,24 @@ func (api *API) PreAuthorizeHandler(next HandleFunc, suffix string) http.Handler
helper
.
Fail500
(
w
,
r
,
err
)
return
}
if
httpResponse
!=
nil
{
defer
func
()
{
httpResponse
.
Body
.
Close
()
}()
}
if
httpResponse
.
StatusCode
!=
http
.
StatusOK
{
// NGINX response buffering is disabled on this path (with
// 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
)
if
err
!=
nil
{
helper
.
Fail500
(
w
,
r
,
err
)
}
httpResponse
.
Body
.
Close
()
// Free up the Unicorn worker
for
k
,
v
:=
range
httpResponse
.
Header
{
// Accomodate broken clients that do case-sensitive header lookup
if
k
==
"Www-Authenticate"
{
...
...
@@ -198,14 +215,12 @@ func (api *API) PreAuthorizeHandler(next HandleFunc, suffix string) http.Handler
}
}
w
.
WriteHeader
(
httpResponse
.
StatusCode
)
io
.
Copy
(
w
,
httpResponse
.
Body
)
httpResponse
.
Body
.
Close
()
io
.
Copy
(
w
,
responseBody
)
return
}
// Close the body immediately, rather than waiting for the next handler
// to complete
httpResponse
.
Body
.
Close
()
httpResponse
.
Body
.
Close
()
// Free up the Unicorn worker
// Negotiate authentication (Kerberos) may need to return a WWW-Authenticate
// header to the client even in case of success as per RFC4559.
...
...
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