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
0592ff1c
Commit
0592ff1c
authored
Dec 17, 2015
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove relativeURIPath from gitReq
parent
a7666718
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
32 deletions
+21
-32
main.go
main.go
+2
-2
servefile.go
servefile.go
+2
-2
servefile_test.go
servefile_test.go
+12
-18
upstream.go
upstream.go
+5
-10
No files found.
main.go
View file @
0592ff1c
...
...
@@ -90,7 +90,7 @@ func compileRoutes(u *upstream) {
// Serve assets
httpRoute
{
""
,
regexp
.
MustCompile
(
`^/assets/`
),
handleServeFile
(
documentRoot
,
CacheExpireMax
,
u
.
handleServeFile
(
documentRoot
,
CacheExpireMax
,
handleDevelopmentMode
(
developmentMode
,
handleDeployPage
(
documentRoot
,
handleRailsError
(
documentRoot
,
...
...
@@ -103,7 +103,7 @@ func compileRoutes(u *upstream) {
// Serve static files or forward the requests
httpRoute
{
""
,
nil
,
handleServeFile
(
documentRoot
,
CacheDisabled
,
u
.
handleServeFile
(
documentRoot
,
CacheDisabled
,
handleDeployPage
(
documentRoot
,
handleRailsError
(
documentRoot
,
u
.
proxyRequest
,
...
...
servefile.go
View file @
0592ff1c
...
...
@@ -16,9 +16,9 @@ const (
CacheExpireMax
)
func
handleServeFile
(
documentRoot
*
string
,
cache
CacheMode
,
notFoundHandler
serviceHandleFunc
)
serviceHandleFunc
{
func
(
u
*
upstream
)
handleServeFile
(
documentRoot
*
string
,
cache
CacheMode
,
notFoundHandler
serviceHandleFunc
)
serviceHandleFunc
{
return
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
file
:=
filepath
.
Join
(
*
documentRoot
,
r
.
relativeURIPath
)
file
:=
filepath
.
Join
(
*
documentRoot
,
u
.
relativeURIPath
(
cleanURIPath
(
r
.
URL
.
Path
))
)
// The filepath.Join does Clean traversing directories up
if
!
strings
.
HasPrefix
(
file
,
*
documentRoot
)
{
...
...
servefile_test.go
View file @
0592ff1c
...
...
@@ -15,12 +15,11 @@ func TestServingNonExistingFile(t *testing.T) {
dir
:=
"/path/to/non/existing/directory"
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/file"
,
nil
)
request
:=
&
gitRequest
{
Request
:
httpRequest
,
relativeURIPath
:
"/static/file"
,
Request
:
httpRequest
,
}
w
:=
httptest
.
NewRecorder
()
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
request
)
newUpstream
(
"http://localhost"
,
nil
)
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
request
)
assertResponseCode
(
t
,
w
,
404
)
}
...
...
@@ -33,26 +32,24 @@ func TestServingDirectory(t *testing.T) {
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/file"
,
nil
)
request
:=
&
gitRequest
{
Request
:
httpRequest
,
relativeURIPath
:
"/"
,
Request
:
httpRequest
,
}
w
:=
httptest
.
NewRecorder
()
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
request
)
newUpstream
(
"http://localhost"
,
nil
)
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
request
)
assertResponseCode
(
t
,
w
,
404
)
}
func
TestServingMalformedUri
(
t
*
testing
.
T
)
{
dir
:=
"/path/to/non/existing/directory"
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/file"
,
nil
)
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/
../../../static/
file"
,
nil
)
request
:=
&
gitRequest
{
Request
:
httpRequest
,
relativeURIPath
:
"/../../../static/file"
,
Request
:
httpRequest
,
}
w
:=
httptest
.
NewRecorder
()
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
request
)
assertResponseCode
(
t
,
w
,
500
)
newUpstream
(
"http://localhost"
,
nil
)
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
request
)
assertResponseCode
(
t
,
w
,
404
)
}
func
TestExecutingHandlerWhenNoFileFound
(
t
*
testing
.
T
)
{
...
...
@@ -60,11 +57,10 @@ func TestExecutingHandlerWhenNoFileFound(t *testing.T) {
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/file"
,
nil
)
request
:=
&
gitRequest
{
Request
:
httpRequest
,
relativeURIPath
:
"/static/file"
,
}
executed
:=
false
handleServeFile
(
&
dir
,
CacheDisabled
,
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
newUpstream
(
"http://localhost"
,
nil
)
.
handleServeFile
(
&
dir
,
CacheDisabled
,
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
executed
=
(
r
==
request
)
})(
nil
,
request
)
if
!
executed
{
...
...
@@ -81,15 +77,14 @@ func TestServingTheActualFile(t *testing.T) {
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/file"
,
nil
)
request
:=
&
gitRequest
{
Request
:
httpRequest
,
relativeURIPath
:
"/file"
,
Request
:
httpRequest
,
}
fileContent
:=
"STATIC"
ioutil
.
WriteFile
(
filepath
.
Join
(
dir
,
"file"
),
[]
byte
(
fileContent
),
0600
)
w
:=
httptest
.
NewRecorder
()
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
request
)
newUpstream
(
"http://localhost"
,
nil
)
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
request
)
assertResponseCode
(
t
,
w
,
200
)
if
w
.
Body
.
String
()
!=
fileContent
{
t
.
Error
(
"We should serve the file: "
,
w
.
Body
.
String
())
...
...
@@ -106,7 +101,6 @@ func testServingThePregzippedFile(t *testing.T, enableGzip bool) {
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/file"
,
nil
)
request
:=
&
gitRequest
{
Request
:
httpRequest
,
relativeURIPath
:
"/file"
,
}
if
enableGzip
{
...
...
@@ -124,7 +118,7 @@ func testServingThePregzippedFile(t *testing.T, enableGzip bool) {
ioutil
.
WriteFile
(
filepath
.
Join
(
dir
,
"file"
),
[]
byte
(
fileContent
),
0600
)
w
:=
httptest
.
NewRecorder
()
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
request
)
newUpstream
(
"http://localhost"
,
nil
)
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
request
)
assertResponseCode
(
t
,
w
,
200
)
if
enableGzip
{
assertResponseHeader
(
t
,
w
,
"Content-Encoding"
,
"gzip"
)
...
...
upstream.go
View file @
0592ff1c
...
...
@@ -57,9 +57,6 @@ type authorizationResponse struct {
type
gitRequest
struct
{
*
http
.
Request
authorizationResponse
// This field contains the URL.Path stripped from RelativeUrlRoot
relativeURIPath
string
}
func
newUpstream
(
authBackend
string
,
authTransport
http
.
RoundTripper
)
*
upstream
{
...
...
@@ -87,6 +84,10 @@ func newUpstream(authBackend string, authTransport http.RoundTripper) *upstream
return
up
}
func
(
u
*
upstream
)
relativeURIPath
(
p
string
)
string
{
return
cleanURIPath
(
strings
.
TrimPrefix
(
p
,
u
.
relativeURLRoot
))
}
func
(
u
*
upstream
)
ServeHTTP
(
ow
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
var
g
httpRoute
...
...
@@ -112,11 +113,6 @@ func (u *upstream) ServeHTTP(ow http.ResponseWriter, r *http.Request) {
return
}
// Strip prefix and add "/"
// To match against non-relative URL
// Making it simpler for our matcher
relativeURIPath
:=
cleanURIPath
(
strings
.
TrimPrefix
(
URIPath
,
u
.
relativeURLRoot
))
// Look for a matching Git service
foundService
:=
false
for
_
,
g
=
range
httpRoutes
{
...
...
@@ -124,7 +120,7 @@ func (u *upstream) ServeHTTP(ow http.ResponseWriter, r *http.Request) {
continue
}
if
g
.
regex
==
nil
||
g
.
regex
.
MatchString
(
relativeURIPath
)
{
if
g
.
regex
==
nil
||
g
.
regex
.
MatchString
(
u
.
relativeURIPath
(
URIPath
)
)
{
foundService
=
true
break
}
...
...
@@ -138,7 +134,6 @@ func (u *upstream) ServeHTTP(ow http.ResponseWriter, r *http.Request) {
request
:=
gitRequest
{
Request
:
r
,
relativeURIPath
:
relativeURIPath
,
}
g
.
handleFunc
(
&
w
,
&
request
)
...
...
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