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
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-workhorse
Commits
cff33472
Commit
cff33472
authored
Dec 09, 2015
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support relativeUrlRoot allowing to serve the app from subpath
parent
3920a26e
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
20 additions
and
8 deletions
+20
-8
error_pages.go
error_pages.go
+1
-1
main.go
main.go
+7
-1
sendfile.go
sendfile.go
+2
-2
servefile.go
servefile.go
+1
-1
upstream.go
upstream.go
+9
-3
No files found.
error_pages.go
View file @
cff33472
...
...
@@ -3,8 +3,8 @@ package main
import
(
"fmt"
"io/ioutil"
"net/http"
"log"
"net/http"
)
type
errorPageResponseWriter
struct
{
...
...
main.go
View file @
cff33472
...
...
@@ -22,6 +22,7 @@ import (
_
"net/http/pprof"
"os"
"regexp"
"strings"
"syscall"
"time"
)
...
...
@@ -35,6 +36,7 @@ var listenUmask = flag.Int("listenUmask", 022, "Umask for Unix socket, default:
var
authBackend
=
flag
.
String
(
"authBackend"
,
"http://localhost:8080"
,
"Authentication/authorization backend"
)
var
authSocket
=
flag
.
String
(
"authSocket"
,
""
,
"Optional: Unix domain socket to dial authBackend at"
)
var
pprofListenAddr
=
flag
.
String
(
"pprofListenAddr"
,
""
,
"pprof listening address, e.g. 'localhost:6060'"
)
var
relativeUrlRoot
=
flag
.
String
(
"relativeUrlRoot"
,
"/"
,
"GitLab relative URL root"
)
type
httpRoute
struct
{
method
string
...
...
@@ -84,6 +86,10 @@ func main() {
os
.
Exit
(
0
)
}
if
!
strings
.
HasSuffix
(
*
relativeUrlRoot
,
"/"
)
{
*
relativeUrlRoot
+=
"/"
}
log
.
Printf
(
"Starting %s"
,
version
)
// Good housekeeping for Unix sockets: unlink before binding
...
...
@@ -128,6 +134,6 @@ func main() {
// Because net/http/pprof installs itself in the DefaultServeMux
// we create a fresh one for the Git server.
serveMux
:=
http
.
NewServeMux
()
serveMux
.
Handle
(
"/"
,
newUpstream
(
*
authBackend
,
authTransport
))
serveMux
.
Handle
(
*
relativeUrlRoot
,
newUpstream
(
*
authBackend
,
authTransport
))
log
.
Fatal
(
http
.
Serve
(
listener
,
serveMux
))
}
sendfile.go
View file @
cff33472
servefile.go
View file @
cff33472
...
...
@@ -16,7 +16,7 @@ func handleServeFile(rootDir string, notFoundHandler serviceHandleFunc) serviceH
}
return
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
file
:=
filepath
.
Join
(
rootDir
,
r
.
URL
.
Path
)
file
:=
filepath
.
Join
(
rootDir
,
r
.
relativeUri
Path
)
file
,
err
:=
filepath
.
Abs
(
file
)
if
err
!=
nil
{
fail500
(
w
,
fmt
.
Errorf
(
"invalid path:"
+
file
,
err
))
...
...
upstream.go
View file @
cff33472
...
...
@@ -11,6 +11,7 @@ import (
"net/http"
"net/http/httputil"
"net/url"
"strings"
)
type
serviceHandleFunc
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
...
...
@@ -53,6 +54,7 @@ type authorizationResponse struct {
// GitLab Rails application.
type
gitRequest
struct
{
*
http
.
Request
relativeUriPath
string
authorizationResponse
u
*
upstream
}
...
...
@@ -78,6 +80,9 @@ func (u *upstream) ServeHTTP(ow http.ResponseWriter, r *http.Request) {
w
:=
newLoggingResponseWriter
(
ow
)
defer
w
.
Log
(
r
)
// Strip prefix and add "/"
relativeUriPath
:=
"/"
+
strings
.
TrimPrefix
(
r
.
RequestURI
,
*
relativeUrlRoot
)
// Look for a matching Git service
foundService
:=
false
for
_
,
g
=
range
httpRoutes
{
...
...
@@ -85,7 +90,7 @@ func (u *upstream) ServeHTTP(ow http.ResponseWriter, r *http.Request) {
continue
}
if
g
.
regex
==
nil
||
g
.
regex
.
MatchString
(
r
.
URL
.
Path
)
{
if
g
.
regex
==
nil
||
g
.
regex
.
MatchString
(
r
elativeUri
Path
)
{
foundService
=
true
break
}
...
...
@@ -99,6 +104,7 @@ func (u *upstream) ServeHTTP(ow http.ResponseWriter, r *http.Request) {
request
:=
gitRequest
{
Request
:
r
,
relativeUriPath
:
relativeUriPath
,
u
:
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