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
ad6c02d2
Commit
ad6c02d2
authored
5 years ago
by
Jacob Vosmaer
Committed by
Nick Thomas
5 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify badgateway RoundTripper
parent
f2b5a96b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
28 deletions
+30
-28
internal/badgateway/roundtripper.go
internal/badgateway/roundtripper.go
+30
-28
No files found.
internal/badgateway/roundtripper.go
View file @
ad6c02d2
...
...
@@ -23,9 +23,13 @@ func NewRoundTripper(developmentMode bool, next http.RoundTripper) http.RoundTri
return
&
roundTripper
{
next
:
next
,
developmentMode
:
developmentMode
}
}
func
(
t
*
roundTripper
)
RoundTrip
(
r
*
http
.
Request
)
(
res
*
http
.
Response
,
err
error
)
{
func
(
t
*
roundTripper
)
RoundTrip
(
r
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
start
:=
time
.
Now
()
res
,
err
=
t
.
next
.
RoundTrip
(
r
)
res
,
err
:=
t
.
next
.
RoundTrip
(
r
)
if
err
==
nil
{
return
res
,
err
}
// httputil.ReverseProxy translates all errors from this
// RoundTrip function into 500 errors. But the most likely error
...
...
@@ -33,31 +37,29 @@ func (t *roundTripper) RoundTrip(r *http.Request) (res *http.Response, err error
// and administrators expect to see a 502 error. To show 502s
// instead of 500s we catch the RoundTrip error here and inject a
// 502 response.
if
err
!=
nil
{
helper
.
LogError
(
r
,
&
sentryError
{
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
),
Request
:
r
,
ProtoMajor
:
r
.
ProtoMajor
,
ProtoMinor
:
r
.
ProtoMinor
,
Proto
:
r
.
Proto
,
Header
:
make
(
http
.
Header
),
Trailer
:
make
(
http
.
Header
),
Body
:
ioutil
.
NopCloser
(
bytes
.
NewBufferString
(
message
)),
}
res
.
Header
.
Set
(
"Content-Type"
,
"text/plain"
)
err
=
nil
helper
.
LogError
(
r
,
&
sentryError
{
fmt
.
Errorf
(
"badgateway: failed after %.fs: %v"
,
time
.
Since
(
start
)
.
Seconds
(),
err
)},
)
message
:=
"GitLab is not responding"
if
t
.
developmentMode
{
message
=
err
.
Error
()
}
return
injectedResponse
:=
&
http
.
Response
{
StatusCode
:
http
.
StatusBadGateway
,
Status
:
http
.
StatusText
(
http
.
StatusBadGateway
),
Request
:
r
,
ProtoMajor
:
r
.
ProtoMajor
,
ProtoMinor
:
r
.
ProtoMinor
,
Proto
:
r
.
Proto
,
Header
:
make
(
http
.
Header
),
Trailer
:
make
(
http
.
Header
),
Body
:
ioutil
.
NopCloser
(
bytes
.
NewBufferString
(
message
)),
}
injectedResponse
.
Header
.
Set
(
"Content-Type"
,
"text/plain"
)
return
injectedResponse
,
nil
}
This diff is collapsed.
Click to expand it.
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