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
a827a033
Commit
a827a033
authored
Dec 18, 2015
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move routes into route.go
parent
70f191d2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
84 deletions
+88
-84
route.go
route.go
+83
-0
upstream.go
upstream.go
+5
-84
No files found.
route.go
0 → 100644
View file @
a827a033
package
main
import
(
"./internal/errorpage"
"./internal/git"
"./internal/lfs"
"net/http"
"regexp"
)
type
route
struct
{
method
string
regex
*
regexp
.
Regexp
handler
http
.
Handler
}
const
projectPattern
=
`^/[^/]+/[^/]+/`
const
gitProjectPattern
=
`^/[^/]+/[^/]+\.git/`
const
apiPattern
=
`^/api/`
const
projectsAPIPattern
=
`^/api/v3/projects/[^/]+/`
const
ciAPIPattern
=
`^/ci/api/`
// Routing table
// We match against URI not containing the relativeUrlRoot:
// see upstream.ServeHTTP
var
routes
[]
route
func
(
u
*
upstream
)
compileRoutes
()
{
u
.
routes
=
[]
route
{
// Git Clone
route
{
"GET"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`info/refs\z`
),
git
.
GetInfoRefs
(
u
.
API
)},
route
{
"POST"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`git-upload-pack\z`
),
contentEncodingHandler
(
git
.
PostRPC
(
u
.
API
))},
route
{
"POST"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`git-receive-pack\z`
),
contentEncodingHandler
(
git
.
PostRPC
(
u
.
API
))},
route
{
"PUT"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`gitlab-lfs/objects/([0-9a-f]{64})/([0-9]+)\z`
),
lfs
.
PutStore
(
u
.
API
,
u
.
Proxy
)},
// Repository Archive
route
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive\z`
),
git
.
GetArchive
(
u
.
API
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.zip\z`
),
git
.
GetArchive
(
u
.
API
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.tar\z`
),
git
.
GetArchive
(
u
.
API
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.tar.gz\z`
),
git
.
GetArchive
(
u
.
API
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.tar.bz2\z`
),
git
.
GetArchive
(
u
.
API
)},
// Repository Archive API
route
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive\z`
),
git
.
GetArchive
(
u
.
API
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.zip\z`
),
git
.
GetArchive
(
u
.
API
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.tar\z`
),
git
.
GetArchive
(
u
.
API
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.tar.gz\z`
),
git
.
GetArchive
(
u
.
API
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.tar.bz2\z`
),
git
.
GetArchive
(
u
.
API
)},
// CI Artifacts API
route
{
"POST"
,
regexp
.
MustCompile
(
ciAPIPattern
+
`v1/builds/[0-9]+/artifacts\z`
),
contentEncodingHandler
(
artifactsAuthorizeHandler
(
u
.
API
,
handleFileUploads
(
u
.
Proxy
)))},
// Explicitly u.Proxy API requests
route
{
""
,
regexp
.
MustCompile
(
apiPattern
),
u
.
Proxy
},
route
{
""
,
regexp
.
MustCompile
(
ciAPIPattern
),
u
.
Proxy
},
// Serve assets
route
{
""
,
regexp
.
MustCompile
(
`^/assets/`
),
handleServeFile
(
u
.
DocumentRoot
,
u
.
urlPrefix
,
CacheExpireMax
,
handleDevelopmentMode
(
developmentMode
,
handleDeployPage
(
u
.
DocumentRoot
,
errorpage
.
Inject
(
u
.
DocumentRoot
,
u
.
Proxy
,
),
),
),
),
},
// Serve static files or forward the requests
route
{
""
,
nil
,
handleServeFile
(
u
.
DocumentRoot
,
u
.
urlPrefix
,
CacheDisabled
,
handleDeployPage
(
u
.
DocumentRoot
,
errorpage
.
Inject
(
u
.
DocumentRoot
,
u
.
Proxy
,
),
),
),
},
}
}
upstream.go
View file @
a827a033
...
...
@@ -8,16 +8,12 @@ package main
import
(
"./internal/api"
"./internal/errorpage"
"./internal/git"
"./internal/lfs"
"./internal/proxy"
"fmt"
"log"
"net"
"net/http"
"net/url"
"regexp"
"strings"
"time"
)
...
...
@@ -30,80 +26,6 @@ type upstream struct {
routes
[]
route
}
type
route
struct
{
method
string
regex
*
regexp
.
Regexp
handler
http
.
Handler
}
const
projectPattern
=
`^/[^/]+/[^/]+/`
const
gitProjectPattern
=
`^/[^/]+/[^/]+\.git/`
const
apiPattern
=
`^/api/`
const
projectsAPIPattern
=
`^/api/v3/projects/[^/]+/`
const
ciAPIPattern
=
`^/ci/api/`
// Routing table
// We match against URI not containing the relativeUrlRoot:
// see upstream.ServeHTTP
var
routes
[]
route
func
(
u
*
upstream
)
compileRoutes
()
{
u
.
routes
=
[]
route
{
// Git Clone
route
{
"GET"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`info/refs\z`
),
git
.
GetInfoRefs
(
u
.
API
)},
route
{
"POST"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`git-upload-pack\z`
),
contentEncodingHandler
(
git
.
PostRPC
(
u
.
API
))},
route
{
"POST"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`git-receive-pack\z`
),
contentEncodingHandler
(
git
.
PostRPC
(
u
.
API
))},
route
{
"PUT"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`gitlab-lfs/objects/([0-9a-f]{64})/([0-9]+)\z`
),
lfs
.
PutStore
(
u
.
API
,
u
.
Proxy
)},
// Repository Archive
route
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive\z`
),
git
.
GetArchive
(
u
.
API
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.zip\z`
),
git
.
GetArchive
(
u
.
API
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.tar\z`
),
git
.
GetArchive
(
u
.
API
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.tar.gz\z`
),
git
.
GetArchive
(
u
.
API
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.tar.bz2\z`
),
git
.
GetArchive
(
u
.
API
)},
// Repository Archive API
route
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive\z`
),
git
.
GetArchive
(
u
.
API
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.zip\z`
),
git
.
GetArchive
(
u
.
API
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.tar\z`
),
git
.
GetArchive
(
u
.
API
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.tar.gz\z`
),
git
.
GetArchive
(
u
.
API
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.tar.bz2\z`
),
git
.
GetArchive
(
u
.
API
)},
// CI Artifacts API
route
{
"POST"
,
regexp
.
MustCompile
(
ciAPIPattern
+
`v1/builds/[0-9]+/artifacts\z`
),
contentEncodingHandler
(
artifactsAuthorizeHandler
(
u
.
API
,
handleFileUploads
(
u
.
Proxy
)))},
// Explicitly u.Proxy API requests
route
{
""
,
regexp
.
MustCompile
(
apiPattern
),
u
.
Proxy
},
route
{
""
,
regexp
.
MustCompile
(
ciAPIPattern
),
u
.
Proxy
},
// Serve assets
route
{
""
,
regexp
.
MustCompile
(
`^/assets/`
),
handleServeFile
(
u
.
DocumentRoot
,
u
.
urlPrefix
,
CacheExpireMax
,
handleDevelopmentMode
(
developmentMode
,
handleDeployPage
(
u
.
DocumentRoot
,
errorpage
.
Inject
(
u
.
DocumentRoot
,
u
.
Proxy
,
),
),
),
),
},
// Serve static files or forward the requests
route
{
""
,
nil
,
handleServeFile
(
u
.
DocumentRoot
,
u
.
urlPrefix
,
CacheDisabled
,
handleDeployPage
(
u
.
DocumentRoot
,
errorpage
.
Inject
(
u
.
DocumentRoot
,
u
.
Proxy
,
),
),
),
},
}
}
func
newUpstream
(
authBackend
string
,
authSocket
string
)
*
upstream
{
parsedURL
,
err
:=
url
.
Parse
(
authBackend
)
if
err
!=
nil
{
...
...
@@ -146,8 +68,6 @@ func newUpstream(authBackend string, authSocket string) *upstream {
}
func
(
u
*
upstream
)
ServeHTTP
(
ow
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
var
g
route
w
:=
newLoggingResponseWriter
(
ow
)
defer
w
.
Log
(
r
)
...
...
@@ -172,13 +92,14 @@ func (u *upstream) ServeHTTP(ow http.ResponseWriter, r *http.Request) {
}
// Look for a matching Git service
var
ro
route
foundService
:=
false
for
_
,
g
=
range
u
.
routes
{
if
g
.
method
!=
""
&&
r
.
Method
!=
g
.
method
{
for
_
,
ro
=
range
u
.
routes
{
if
ro
.
method
!=
""
&&
r
.
Method
!=
ro
.
method
{
continue
}
if
g
.
regex
==
nil
||
g
.
regex
.
MatchString
(
prefix
.
strip
(
URIPath
))
{
if
ro
.
regex
==
nil
||
ro
.
regex
.
MatchString
(
prefix
.
strip
(
URIPath
))
{
foundService
=
true
break
}
...
...
@@ -190,5 +111,5 @@ func (u *upstream) ServeHTTP(ow http.ResponseWriter, r *http.Request) {
return
}
g
.
handler
.
ServeHTTP
(
&
w
,
r
)
ro
.
handler
.
ServeHTTP
(
&
w
,
r
)
}
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