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
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-workhorse
Commits
69e801cf
Commit
69e801cf
authored
Jan 13, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Eagerly initialize badgateway.RoundTripper
parent
9f0b3f71
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
22 additions
and
37 deletions
+22
-37
internal/api/api.go
internal/api/api.go
+6
-7
internal/badgateway/roundtripper.go
internal/badgateway/roundtripper.go
+13
-24
internal/proxy/proxy.go
internal/proxy/proxy.go
+1
-1
internal/upstream/upstream.go
internal/upstream/upstream.go
+1
-4
main_test.go
main_test.go
+1
-1
No files found.
internal/api/api.go
View file @
69e801cf
...
...
@@ -19,16 +19,15 @@ type API struct {
Version
string
}
func
NewAPI
(
myURL
*
url
.
URL
,
version
string
,
roundtripper
*
badgateway
.
RoundTripper
)
*
API
{
a
:=
API
{
Client
:
&
http
.
Client
{
Transport
:
&
badgateway
.
RoundTripper
{}},
func
NewAPI
(
myURL
*
url
.
URL
,
version
string
,
roundTripper
*
badgateway
.
RoundTripper
)
*
API
{
if
roundTripper
==
nil
{
roundTripper
=
badgateway
.
NewRoundTripper
(
""
,
0
)
}
return
&
API
{
Client
:
&
http
.
Client
{
Transport
:
roundTripper
},
URL
:
myURL
,
Version
:
version
,
}
if
roundtripper
!=
nil
{
a
.
Client
.
Transport
=
roundtripper
}
return
&
a
}
type
HandleFunc
func
(
http
.
ResponseWriter
,
*
http
.
Request
,
*
Response
)
...
...
internal/badgateway/roundtripper.go
View file @
69e801cf
...
...
@@ -7,7 +7,6 @@ import (
"io/ioutil"
"net"
"net/http"
"sync"
"time"
)
...
...
@@ -24,15 +23,22 @@ var DefaultTransport = &http.Transport{
}
type
RoundTripper
struct
{
Socket
string
ProxyHeadersTimeout
time
.
Duration
Transport
*
http
.
Transport
configureRoundTripperOnce
sync
.
Once
Transport
*
http
.
Transport
}
func
(
t
*
RoundTripper
)
RoundTrip
(
r
*
http
.
Request
)
(
res
*
http
.
Response
,
err
error
)
{
t
.
configureRoundTripperOnce
.
Do
(
t
.
configureRoundTripper
)
func
NewRoundTripper
(
socket
string
,
proxyHeadersTimeout
time
.
Duration
)
*
RoundTripper
{
tr
:=
*
DefaultTransport
tr
.
ResponseHeaderTimeout
=
proxyHeadersTimeout
if
socket
!=
""
{
tr
.
Dial
=
func
(
_
,
_
string
)
(
net
.
Conn
,
error
)
{
return
DefaultDialer
.
Dial
(
"unix"
,
socket
)
}
}
return
&
RoundTripper
{
Transport
:
&
tr
}
}
func
(
t
*
RoundTripper
)
RoundTrip
(
r
*
http
.
Request
)
(
res
*
http
.
Response
,
err
error
)
{
res
,
err
=
t
.
Transport
.
RoundTrip
(
r
)
// httputil.ReverseProxy translates all errors from this
...
...
@@ -61,20 +67,3 @@ func (t *RoundTripper) RoundTrip(r *http.Request) (res *http.Response, err error
}
return
}
func
(
t
*
RoundTripper
)
configureRoundTripper
()
{
if
t
.
Transport
!=
nil
{
return
}
tr
:=
*
DefaultTransport
tr
.
ResponseHeaderTimeout
=
t
.
ProxyHeadersTimeout
if
t
.
Socket
!=
""
{
tr
.
Dial
=
func
(
_
,
_
string
)
(
net
.
Conn
,
error
)
{
return
DefaultDialer
.
Dial
(
"unix"
,
t
.
Socket
)
}
}
t
.
Transport
=
&
tr
}
internal/proxy/proxy.go
View file @
69e801cf
...
...
@@ -24,7 +24,7 @@ func (p *Proxy) reverseProxy() *httputil.ReverseProxy {
if
p
.
RoundTripper
!=
nil
{
p
.
_reverseProxy
.
Transport
=
p
.
RoundTripper
}
else
{
p
.
_reverseProxy
.
Transport
=
&
badgateway
.
RoundTripper
{}
p
.
_reverseProxy
.
Transport
=
badgateway
.
NewRoundTripper
(
""
,
0
)
}
})
return
p
.
_reverseProxy
...
...
internal/upstream/upstream.go
View file @
69e801cf
...
...
@@ -62,10 +62,7 @@ func (u *Upstream) configureURLPrefix() {
func
(
u
*
Upstream
)
RoundTripper
()
*
badgateway
.
RoundTripper
{
u
.
configureRoundTripperOnce
.
Do
(
func
()
{
u
.
roundtripper
=
&
badgateway
.
RoundTripper
{
Socket
:
u
.
Socket
,
ProxyHeadersTimeout
:
u
.
ProxyHeadersTimeout
,
}
u
.
roundtripper
=
badgateway
.
NewRoundTripper
(
u
.
Socket
,
u
.
ProxyHeadersTimeout
)
})
return
u
.
roundtripper
...
...
main_test.go
View file @
69e801cf
...
...
@@ -511,7 +511,7 @@ func startWorkhorseServer(authBackend string) *httptest.Server {
"123"
,
testDocumentRoot
,
false
,
time
.
Minute
,
0
,
)
return
httptest
.
NewServer
(
u
)
}
...
...
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