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
iv
gitlab-workhorse
Commits
9f0b3f71
Commit
9f0b3f71
authored
Jan 13, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use eager initialization for Upstream.URLPrefix
parent
a202aadc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
20 deletions
+15
-20
internal/upstream/routes.go
internal/upstream/routes.go
+2
-2
internal/upstream/upstream.go
internal/upstream/upstream.go
+13
-18
No files found.
internal/upstream/routes.go
View file @
9f0b3f71
...
@@ -73,7 +73,7 @@ func (u *Upstream) configureRoutes() {
...
@@ -73,7 +73,7 @@ func (u *Upstream) configureRoutes() {
// Serve assets
// Serve assets
route
{
""
,
regexp
.
MustCompile
(
`^/assets/`
),
route
{
""
,
regexp
.
MustCompile
(
`^/assets/`
),
static
.
ServeExisting
(
u
.
URLPrefix
()
,
staticpages
.
CacheExpireMax
,
static
.
ServeExisting
(
u
.
URLPrefix
,
staticpages
.
CacheExpireMax
,
NotFoundUnless
(
u
.
DevelopmentMode
,
NotFoundUnless
(
u
.
DevelopmentMode
,
proxy
,
proxy
,
),
),
...
@@ -88,7 +88,7 @@ func (u *Upstream) configureRoutes() {
...
@@ -88,7 +88,7 @@ func (u *Upstream) configureRoutes() {
// Serve static files or forward the requests
// Serve static files or forward the requests
route
{
""
,
nil
,
route
{
""
,
nil
,
static
.
ServeExisting
(
u
.
URLPrefix
()
,
staticpages
.
CacheDisabled
,
static
.
ServeExisting
(
u
.
URLPrefix
,
staticpages
.
CacheDisabled
,
static
.
DeployPage
(
static
.
DeployPage
(
static
.
ErrorPages
(
u
.
DevelopmentMode
,
static
.
ErrorPages
(
u
.
DevelopmentMode
,
proxy
,
proxy
,
...
...
internal/upstream/upstream.go
View file @
9f0b3f71
...
@@ -28,10 +28,8 @@ type Upstream struct {
...
@@ -28,10 +28,8 @@ type Upstream struct {
DevelopmentMode
bool
DevelopmentMode
bool
ProxyHeadersTimeout
time
.
Duration
ProxyHeadersTimeout
time
.
Duration
urlPrefix
urlprefix
.
Prefix
URLPrefix
urlprefix
.
Prefix
configureURLPrefixOnce
sync
.
Once
Routes
[]
route
Routes
[]
route
roundtripper
*
badgateway
.
RoundTripper
roundtripper
*
badgateway
.
RoundTripper
configureRoundTripperOnce
sync
.
Once
configureRoundTripperOnce
sync
.
Once
...
@@ -46,23 +44,20 @@ func NewUpstream(backend *url.URL, socket string, version string, documentRoot s
...
@@ -46,23 +44,20 @@ func NewUpstream(backend *url.URL, socket string, version string, documentRoot s
DevelopmentMode
:
developmentMode
,
DevelopmentMode
:
developmentMode
,
ProxyHeadersTimeout
:
proxyHeadersTimeout
,
ProxyHeadersTimeout
:
proxyHeadersTimeout
,
}
}
if
backend
==
nil
{
up
.
Backend
=
DefaultBackend
}
up
.
configureRoutes
()
up
.
configureRoutes
()
up
.
configureURLPrefix
()
return
&
up
return
&
up
}
}
func
(
u
*
Upstream
)
URLPrefix
()
urlprefix
.
Prefix
{
func
(
u
*
Upstream
)
configureURLPrefix
()
{
u
.
configureURLPrefixOnce
.
Do
(
func
()
{
relativeURLRoot
:=
u
.
Backend
.
Path
if
u
.
Backend
==
nil
{
if
!
strings
.
HasSuffix
(
relativeURLRoot
,
"/"
)
{
u
.
Backend
=
DefaultBackend
relativeURLRoot
+=
"/"
}
}
relativeURLRoot
:=
u
.
Backend
.
Path
u
.
URLPrefix
=
urlprefix
.
Prefix
(
relativeURLRoot
)
if
!
strings
.
HasSuffix
(
relativeURLRoot
,
"/"
)
{
relativeURLRoot
+=
"/"
}
u
.
urlPrefix
=
urlprefix
.
Prefix
(
relativeURLRoot
)
})
return
u
.
urlPrefix
}
}
func
(
u
*
Upstream
)
RoundTripper
()
*
badgateway
.
RoundTripper
{
func
(
u
*
Upstream
)
RoundTripper
()
*
badgateway
.
RoundTripper
{
...
@@ -94,7 +89,7 @@ func (u *Upstream) ServeHTTP(ow http.ResponseWriter, r *http.Request) {
...
@@ -94,7 +89,7 @@ func (u *Upstream) ServeHTTP(ow http.ResponseWriter, r *http.Request) {
// Check URL Root
// Check URL Root
URIPath
:=
urlprefix
.
CleanURIPath
(
r
.
URL
.
Path
)
URIPath
:=
urlprefix
.
CleanURIPath
(
r
.
URL
.
Path
)
prefix
:=
u
.
URLPrefix
()
prefix
:=
u
.
URLPrefix
if
!
prefix
.
Match
(
URIPath
)
{
if
!
prefix
.
Match
(
URIPath
)
{
httpError
(
&
w
,
r
,
fmt
.
Sprintf
(
"Not found %q"
,
URIPath
),
http
.
StatusNotFound
)
httpError
(
&
w
,
r
,
fmt
.
Sprintf
(
"Not found %q"
,
URIPath
),
http
.
StatusNotFound
)
return
return
...
...
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