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
da533228
Commit
da533228
authored
Dec 15, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stop leaking error messages in 502 responses
parent
5aa350e3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
7 deletions
+13
-7
internal/badgateway/roundtripper.go
internal/badgateway/roundtripper.go
+11
-5
internal/upstream/upstream.go
internal/upstream/upstream.go
+1
-1
proxy_test.go
proxy_test.go
+1
-1
No files found.
internal/badgateway/roundtripper.go
View file @
da533228
...
...
@@ -28,14 +28,15 @@ var DefaultTransport = &http.Transport{
type
Error
struct
{
error
}
type
RoundTripper
struct
{
Transport
*
http
.
Transport
Transport
*
http
.
Transport
developmentMode
bool
}
func
TestRoundTripper
(
backend
*
url
.
URL
)
*
RoundTripper
{
return
NewRoundTripper
(
backend
,
""
,
0
)
return
NewRoundTripper
(
backend
,
""
,
0
,
true
)
}
func
NewRoundTripper
(
backend
*
url
.
URL
,
socket
string
,
proxyHeadersTimeout
time
.
Duration
)
*
RoundTripper
{
func
NewRoundTripper
(
backend
*
url
.
URL
,
socket
string
,
proxyHeadersTimeout
time
.
Duration
,
developmentMode
bool
)
*
RoundTripper
{
tr
:=
*
DefaultTransport
tr
.
ResponseHeaderTimeout
=
proxyHeadersTimeout
...
...
@@ -52,7 +53,7 @@ func NewRoundTripper(backend *url.URL, socket string, proxyHeadersTimeout time.D
panic
(
"backend is nil and socket is empty"
)
}
return
&
RoundTripper
{
Transport
:
&
tr
}
return
&
RoundTripper
{
Transport
:
&
tr
,
developmentMode
:
developmentMode
}
}
func
mustParseAddress
(
address
,
scheme
string
)
string
{
...
...
@@ -86,6 +87,11 @@ func (t *RoundTripper) RoundTrip(r *http.Request) (res *http.Response, err error
&
Error
{
fmt
.
Errorf
(
"badgateway: failed after %.fs: %v"
,
time
.
Since
(
start
)
.
Seconds
(),
err
)},
)
message
:=
"GitLab is not responding"
if
t
.
developmentMode
{
message
=
err
.
Error
()
}
res
=
&
http
.
Response
{
StatusCode
:
http
.
StatusBadGateway
,
Status
:
http
.
StatusText
(
http
.
StatusBadGateway
),
...
...
@@ -96,7 +102,7 @@ func (t *RoundTripper) RoundTrip(r *http.Request) (res *http.Response, err error
Proto
:
r
.
Proto
,
Header
:
make
(
http
.
Header
),
Trailer
:
make
(
http
.
Header
),
Body
:
ioutil
.
NopCloser
(
bytes
.
NewBufferString
(
err
.
Error
()
)),
Body
:
ioutil
.
NopCloser
(
bytes
.
NewBufferString
(
message
)),
}
res
.
Header
.
Set
(
"Content-Type"
,
"text/plain"
)
err
=
nil
...
...
internal/upstream/upstream.go
View file @
da533228
...
...
@@ -52,7 +52,7 @@ func NewUpstream(config Config) *Upstream {
if
up
.
Backend
==
nil
{
up
.
Backend
=
DefaultBackend
}
up
.
RoundTripper
=
badgateway
.
NewRoundTripper
(
up
.
Backend
,
up
.
Socket
,
up
.
ProxyHeadersTimeout
)
up
.
RoundTripper
=
badgateway
.
NewRoundTripper
(
up
.
Backend
,
up
.
Socket
,
up
.
ProxyHeadersTimeout
,
config
.
DevelopmentMode
)
up
.
configureURLPrefix
()
up
.
configureRoutes
()
return
&
up
...
...
proxy_test.go
View file @
da533228
...
...
@@ -112,7 +112,7 @@ func TestProxyReadTimeout(t *testing.T) {
w
:=
httptest
.
NewRecorder
()
p
.
ServeHTTP
(
w
,
httpRequest
)
testhelper
.
AssertResponseCode
(
t
,
w
,
502
)
testhelper
.
AssertResponseBody
(
t
,
w
,
"
net/http: timeout awaiting response headers
"
)
testhelper
.
AssertResponseBody
(
t
,
w
,
"
GitLab is not responding
"
)
}
func
TestProxyHandlerTimeout
(
t
*
testing
.
T
)
{
...
...
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