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
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
Kazuhiko Shiozaki
gitlab-workhorse
Commits
d9014671
Commit
d9014671
authored
Jan 13, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initialize routes eagerly in NewUpstream
parent
3ea22ec1
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
22 deletions
+32
-22
internal/upstream/routes.go
internal/upstream/routes.go
+1
-6
internal/upstream/upstream.go
internal/upstream/upstream.go
+15
-3
main.go
main.go
+8
-8
main_test.go
main_test.go
+8
-5
No files found.
internal/upstream/routes.go
View file @
d9014671
...
@@ -30,11 +30,6 @@ const ciAPIPattern = `^/ci/api/`
...
@@ -30,11 +30,6 @@ const ciAPIPattern = `^/ci/api/`
// We match against URI not containing the relativeUrlRoot:
// We match against URI not containing the relativeUrlRoot:
// see upstream.ServeHTTP
// see upstream.ServeHTTP
func
(
u
*
Upstream
)
Routes
()
[]
route
{
u
.
configureRoutesOnce
.
Do
(
u
.
configureRoutes
)
return
u
.
routes
}
func
(
u
*
Upstream
)
configureRoutes
()
{
func
(
u
*
Upstream
)
configureRoutes
()
{
api
:=
&
apipkg
.
API
{
api
:=
&
apipkg
.
API
{
RoundTripper
:
u
.
RoundTripper
(),
RoundTripper
:
u
.
RoundTripper
(),
...
@@ -48,7 +43,7 @@ func (u *Upstream) configureRoutes() {
...
@@ -48,7 +43,7 @@ func (u *Upstream) configureRoutes() {
RoundTripper
:
u
.
RoundTripper
(),
RoundTripper
:
u
.
RoundTripper
(),
}
}
u
.
r
outes
=
[]
route
{
u
.
R
outes
=
[]
route
{
// Git Clone
// Git Clone
route
{
"GET"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`info/refs\z`
),
git
.
GetInfoRefs
(
api
)},
route
{
"GET"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`info/refs\z`
),
git
.
GetInfoRefs
(
api
)},
route
{
"POST"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`git-upload-pack\z`
),
contentEncodingHandler
(
git
.
PostRPC
(
api
))},
route
{
"POST"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`git-upload-pack\z`
),
contentEncodingHandler
(
git
.
PostRPC
(
api
))},
...
...
internal/upstream/upstream.go
View file @
d9014671
...
@@ -31,13 +31,25 @@ type Upstream struct {
...
@@ -31,13 +31,25 @@ type Upstream struct {
urlPrefix
urlprefix
.
Prefix
urlPrefix
urlprefix
.
Prefix
configureURLPrefixOnce
sync
.
Once
configureURLPrefixOnce
sync
.
Once
routes
[]
route
Routes
[]
route
configureRoutesOnce
sync
.
Once
roundtripper
*
badgateway
.
RoundTripper
roundtripper
*
badgateway
.
RoundTripper
configureRoundTripperOnce
sync
.
Once
configureRoundTripperOnce
sync
.
Once
}
}
func
NewUpstream
(
backend
*
url
.
URL
,
socket
string
,
version
string
,
documentRoot
string
,
developmentMode
bool
,
proxyHeadersTimeout
time
.
Duration
)
*
Upstream
{
up
:=
Upstream
{
Backend
:
backend
,
Socket
:
socket
,
Version
:
version
,
DocumentRoot
:
documentRoot
,
DevelopmentMode
:
developmentMode
,
ProxyHeadersTimeout
:
proxyHeadersTimeout
,
}
up
.
configureRoutes
()
return
&
up
}
func
(
u
*
Upstream
)
URLPrefix
()
urlprefix
.
Prefix
{
func
(
u
*
Upstream
)
URLPrefix
()
urlprefix
.
Prefix
{
u
.
configureURLPrefixOnce
.
Do
(
func
()
{
u
.
configureURLPrefixOnce
.
Do
(
func
()
{
if
u
.
Backend
==
nil
{
if
u
.
Backend
==
nil
{
...
@@ -91,7 +103,7 @@ func (u *Upstream) ServeHTTP(ow http.ResponseWriter, r *http.Request) {
...
@@ -91,7 +103,7 @@ func (u *Upstream) ServeHTTP(ow http.ResponseWriter, r *http.Request) {
// Look for a matching Git service
// Look for a matching Git service
var
ro
route
var
ro
route
foundService
:=
false
foundService
:=
false
for
_
,
ro
=
range
u
.
Routes
()
{
for
_
,
ro
=
range
u
.
Routes
{
if
ro
.
method
!=
""
&&
r
.
Method
!=
ro
.
method
{
if
ro
.
method
!=
""
&&
r
.
Method
!=
ro
.
method
{
continue
continue
}
}
...
...
main.go
View file @
d9014671
...
@@ -81,14 +81,14 @@ func main() {
...
@@ -81,14 +81,14 @@ func main() {
}()
}()
}
}
up
:=
&
upstream
.
Upstream
{
up
:=
upstream
.
NewUpstream
(
Backend
:
authBackend
,
authBackend
,
Socket
:
*
authSocket
,
*
authSocket
,
Version
:
Version
,
Version
,
ProxyHeadersTimeout
:
*
proxyHeadersTimeou
t
,
*
documentRoo
t
,
DocumentRoot
:
*
documentRoot
,
*
developmentMode
,
DevelopmentMode
:
*
developmentMode
,
*
proxyHeadersTimeout
,
}
)
log
.
Fatal
(
http
.
Serve
(
listener
,
up
))
log
.
Fatal
(
http
.
Serve
(
listener
,
up
))
}
}
main_test.go
View file @
d9014671
...
@@ -505,11 +505,14 @@ func testAuthServer(url *regexp.Regexp, code int, body interface{}) *httptest.Se
...
@@ -505,11 +505,14 @@ func testAuthServer(url *regexp.Regexp, code int, body interface{}) *httptest.Se
}
}
func
startWorkhorseServer
(
authBackend
string
)
*
httptest
.
Server
{
func
startWorkhorseServer
(
authBackend
string
)
*
httptest
.
Server
{
u
:=
&
upstream
.
Upstream
{
u
:=
upstream
.
NewUpstream
(
Backend
:
helper
.
URLMustParse
(
authBackend
),
helper
.
URLMustParse
(
authBackend
),
Version
:
"123"
,
""
,
DocumentRoot
:
testDocumentRoot
,
"123"
,
}
testDocumentRoot
,
false
,
time
.
Minute
,
)
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