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 {
...
@@ -19,16 +19,15 @@ type API struct {
Version
string
Version
string
}
}
func
NewAPI
(
myURL
*
url
.
URL
,
version
string
,
roundtripper
*
badgateway
.
RoundTripper
)
*
API
{
func
NewAPI
(
myURL
*
url
.
URL
,
version
string
,
roundTripper
*
badgateway
.
RoundTripper
)
*
API
{
a
:=
API
{
if
roundTripper
==
nil
{
Client
:
&
http
.
Client
{
Transport
:
&
badgateway
.
RoundTripper
{}},
roundTripper
=
badgateway
.
NewRoundTripper
(
""
,
0
)
}
return
&
API
{
Client
:
&
http
.
Client
{
Transport
:
roundTripper
},
URL
:
myURL
,
URL
:
myURL
,
Version
:
version
,
Version
:
version
,
}
}
if
roundtripper
!=
nil
{
a
.
Client
.
Transport
=
roundtripper
}
return
&
a
}
}
type
HandleFunc
func
(
http
.
ResponseWriter
,
*
http
.
Request
,
*
Response
)
type
HandleFunc
func
(
http
.
ResponseWriter
,
*
http
.
Request
,
*
Response
)
...
...
internal/badgateway/roundtripper.go
View file @
69e801cf
...
@@ -7,7 +7,6 @@ import (
...
@@ -7,7 +7,6 @@ import (
"io/ioutil"
"io/ioutil"
"net"
"net"
"net/http"
"net/http"
"sync"
"time"
"time"
)
)
...
@@ -24,15 +23,22 @@ var DefaultTransport = &http.Transport{
...
@@ -24,15 +23,22 @@ var DefaultTransport = &http.Transport{
}
}
type
RoundTripper
struct
{
type
RoundTripper
struct
{
Socket
string
Transport
*
http
.
Transport
ProxyHeadersTimeout
time
.
Duration
Transport
*
http
.
Transport
configureRoundTripperOnce
sync
.
Once
}
}
func
(
t
*
RoundTripper
)
RoundTrip
(
r
*
http
.
Request
)
(
res
*
http
.
Response
,
err
error
)
{
func
NewRoundTripper
(
socket
string
,
proxyHeadersTimeout
time
.
Duration
)
*
RoundTripper
{
t
.
configureRoundTripperOnce
.
Do
(
t
.
configureRoundTripper
)
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
)
res
,
err
=
t
.
Transport
.
RoundTrip
(
r
)
// httputil.ReverseProxy translates all errors from this
// httputil.ReverseProxy translates all errors from this
...
@@ -61,20 +67,3 @@ func (t *RoundTripper) RoundTrip(r *http.Request) (res *http.Response, err error
...
@@ -61,20 +67,3 @@ func (t *RoundTripper) RoundTrip(r *http.Request) (res *http.Response, err error
}
}
return
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 {
...
@@ -24,7 +24,7 @@ func (p *Proxy) reverseProxy() *httputil.ReverseProxy {
if
p
.
RoundTripper
!=
nil
{
if
p
.
RoundTripper
!=
nil
{
p
.
_reverseProxy
.
Transport
=
p
.
RoundTripper
p
.
_reverseProxy
.
Transport
=
p
.
RoundTripper
}
else
{
}
else
{
p
.
_reverseProxy
.
Transport
=
&
badgateway
.
RoundTripper
{}
p
.
_reverseProxy
.
Transport
=
badgateway
.
NewRoundTripper
(
""
,
0
)
}
}
})
})
return
p
.
_reverseProxy
return
p
.
_reverseProxy
...
...
internal/upstream/upstream.go
View file @
69e801cf
...
@@ -62,10 +62,7 @@ func (u *Upstream) configureURLPrefix() {
...
@@ -62,10 +62,7 @@ func (u *Upstream) configureURLPrefix() {
func
(
u
*
Upstream
)
RoundTripper
()
*
badgateway
.
RoundTripper
{
func
(
u
*
Upstream
)
RoundTripper
()
*
badgateway
.
RoundTripper
{
u
.
configureRoundTripperOnce
.
Do
(
func
()
{
u
.
configureRoundTripperOnce
.
Do
(
func
()
{
u
.
roundtripper
=
&
badgateway
.
RoundTripper
{
u
.
roundtripper
=
badgateway
.
NewRoundTripper
(
u
.
Socket
,
u
.
ProxyHeadersTimeout
)
Socket
:
u
.
Socket
,
ProxyHeadersTimeout
:
u
.
ProxyHeadersTimeout
,
}
})
})
return
u
.
roundtripper
return
u
.
roundtripper
...
...
main_test.go
View file @
69e801cf
...
@@ -511,7 +511,7 @@ func startWorkhorseServer(authBackend string) *httptest.Server {
...
@@ -511,7 +511,7 @@ func startWorkhorseServer(authBackend string) *httptest.Server {
"123"
,
"123"
,
testDocumentRoot
,
testDocumentRoot
,
false
,
false
,
time
.
Minute
,
0
,
)
)
return
httptest
.
NewServer
(
u
)
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