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
1559a5f7
Commit
1559a5f7
authored
Dec 18, 2015
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
No longer use global *documentRoot
parent
de0cffc2
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
23 additions
and
20 deletions
+23
-20
deploy_page.go
deploy_page.go
+2
-2
deploy_page_test.go
deploy_page_test.go
+2
-2
main.go
main.go
+3
-1
servefile.go
servefile.go
+3
-3
servefile_test.go
servefile_test.go
+6
-6
upstream.go
upstream.go
+7
-6
No files found.
deploy_page.go
View file @
1559a5f7
...
@@ -7,9 +7,9 @@ import (
...
@@ -7,9 +7,9 @@ import (
"path/filepath"
"path/filepath"
)
)
func
handleDeployPage
(
documentRoot
*
string
,
handler
http
.
Handler
)
http
.
HandlerFunc
{
func
handleDeployPage
(
documentRoot
string
,
handler
http
.
Handler
)
http
.
HandlerFunc
{
return
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
return
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
deployPage
:=
filepath
.
Join
(
*
documentRoot
,
"index.html"
)
deployPage
:=
filepath
.
Join
(
documentRoot
,
"index.html"
)
data
,
err
:=
ioutil
.
ReadFile
(
deployPage
)
data
,
err
:=
ioutil
.
ReadFile
(
deployPage
)
if
err
!=
nil
{
if
err
!=
nil
{
handler
.
ServeHTTP
(
w
,
r
)
handler
.
ServeHTTP
(
w
,
r
)
...
...
deploy_page_test.go
View file @
1559a5f7
...
@@ -20,7 +20,7 @@ func TestIfNoDeployPageExist(t *testing.T) {
...
@@ -20,7 +20,7 @@ func TestIfNoDeployPageExist(t *testing.T) {
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
executed
:=
false
executed
:=
false
handleDeployPage
(
&
dir
,
http
.
HandlerFunc
(
func
(
_
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
handleDeployPage
(
dir
,
http
.
HandlerFunc
(
func
(
_
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
executed
=
true
executed
=
true
}))(
w
,
nil
)
}))(
w
,
nil
)
if
!
executed
{
if
!
executed
{
...
@@ -41,7 +41,7 @@ func TestIfDeployPageExist(t *testing.T) {
...
@@ -41,7 +41,7 @@ func TestIfDeployPageExist(t *testing.T) {
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
executed
:=
false
executed
:=
false
handleDeployPage
(
&
dir
,
http
.
HandlerFunc
(
func
(
_
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
handleDeployPage
(
dir
,
http
.
HandlerFunc
(
func
(
_
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
executed
=
true
executed
=
true
}))(
w
,
nil
)
}))(
w
,
nil
)
if
executed
{
if
executed
{
...
...
main.go
View file @
1559a5f7
...
@@ -80,5 +80,7 @@ func main() {
...
@@ -80,5 +80,7 @@ func main() {
}()
}()
}
}
log
.
Fatal
(
http
.
Serve
(
listener
,
newUpstream
(
*
authBackend
,
*
authSocket
)))
upstream
:=
newUpstream
(
*
authBackend
,
*
authSocket
)
upstream
.
DocumentRoot
=
*
documentRoot
log
.
Fatal
(
http
.
Serve
(
listener
,
upstream
))
}
}
servefile.go
View file @
1559a5f7
...
@@ -17,12 +17,12 @@ const (
...
@@ -17,12 +17,12 @@ const (
CacheExpireMax
CacheExpireMax
)
)
func
(
u
*
upstream
)
handleServeFile
(
documentRoot
*
string
,
cache
CacheMode
,
notFoundHandler
http
.
HandlerFunc
)
http
.
HandlerFunc
{
func
(
u
*
upstream
)
handleServeFile
(
documentRoot
string
,
cache
CacheMode
,
notFoundHandler
http
.
HandlerFunc
)
http
.
HandlerFunc
{
return
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
return
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
file
:=
filepath
.
Join
(
*
documentRoot
,
u
.
relativeURIPath
(
cleanURIPath
(
r
.
URL
.
Path
)))
file
:=
filepath
.
Join
(
documentRoot
,
u
.
relativeURIPath
(
cleanURIPath
(
r
.
URL
.
Path
)))
// The filepath.Join does Clean traversing directories up
// The filepath.Join does Clean traversing directories up
if
!
strings
.
HasPrefix
(
file
,
*
documentRoot
)
{
if
!
strings
.
HasPrefix
(
file
,
documentRoot
)
{
helper
.
Fail500
(
w
,
&
os
.
PathError
{
helper
.
Fail500
(
w
,
&
os
.
PathError
{
Op
:
"open"
,
Op
:
"open"
,
Path
:
file
,
Path
:
file
,
...
...
servefile_test.go
View file @
1559a5f7
...
@@ -19,7 +19,7 @@ func TestServingNonExistingFile(t *testing.T) {
...
@@ -19,7 +19,7 @@ func TestServingNonExistingFile(t *testing.T) {
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/file"
,
nil
)
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/file"
,
nil
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
dummyUpstream
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
dummyUpstream
.
handleServeFile
(
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
helper
.
AssertResponseCode
(
t
,
w
,
404
)
helper
.
AssertResponseCode
(
t
,
w
,
404
)
}
}
...
@@ -32,7 +32,7 @@ func TestServingDirectory(t *testing.T) {
...
@@ -32,7 +32,7 @@ func TestServingDirectory(t *testing.T) {
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/file"
,
nil
)
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/file"
,
nil
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
dummyUpstream
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
dummyUpstream
.
handleServeFile
(
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
helper
.
AssertResponseCode
(
t
,
w
,
404
)
helper
.
AssertResponseCode
(
t
,
w
,
404
)
}
}
...
@@ -41,7 +41,7 @@ func TestServingMalformedUri(t *testing.T) {
...
@@ -41,7 +41,7 @@ func TestServingMalformedUri(t *testing.T) {
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/../../../static/file"
,
nil
)
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/../../../static/file"
,
nil
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
dummyUpstream
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
dummyUpstream
.
handleServeFile
(
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
helper
.
AssertResponseCode
(
t
,
w
,
404
)
helper
.
AssertResponseCode
(
t
,
w
,
404
)
}
}
...
@@ -50,7 +50,7 @@ func TestExecutingHandlerWhenNoFileFound(t *testing.T) {
...
@@ -50,7 +50,7 @@ func TestExecutingHandlerWhenNoFileFound(t *testing.T) {
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/file"
,
nil
)
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/file"
,
nil
)
executed
:=
false
executed
:=
false
dummyUpstream
.
handleServeFile
(
&
dir
,
CacheDisabled
,
func
(
_
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
dummyUpstream
.
handleServeFile
(
dir
,
CacheDisabled
,
func
(
_
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
executed
=
(
r
==
httpRequest
)
executed
=
(
r
==
httpRequest
)
})(
nil
,
httpRequest
)
})(
nil
,
httpRequest
)
if
!
executed
{
if
!
executed
{
...
@@ -71,7 +71,7 @@ func TestServingTheActualFile(t *testing.T) {
...
@@ -71,7 +71,7 @@ func TestServingTheActualFile(t *testing.T) {
ioutil
.
WriteFile
(
filepath
.
Join
(
dir
,
"file"
),
[]
byte
(
fileContent
),
0600
)
ioutil
.
WriteFile
(
filepath
.
Join
(
dir
,
"file"
),
[]
byte
(
fileContent
),
0600
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
dummyUpstream
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
dummyUpstream
.
handleServeFile
(
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
helper
.
AssertResponseCode
(
t
,
w
,
200
)
helper
.
AssertResponseCode
(
t
,
w
,
200
)
if
w
.
Body
.
String
()
!=
fileContent
{
if
w
.
Body
.
String
()
!=
fileContent
{
t
.
Error
(
"We should serve the file: "
,
w
.
Body
.
String
())
t
.
Error
(
"We should serve the file: "
,
w
.
Body
.
String
())
...
@@ -102,7 +102,7 @@ func testServingThePregzippedFile(t *testing.T, enableGzip bool) {
...
@@ -102,7 +102,7 @@ func testServingThePregzippedFile(t *testing.T, enableGzip bool) {
ioutil
.
WriteFile
(
filepath
.
Join
(
dir
,
"file"
),
[]
byte
(
fileContent
),
0600
)
ioutil
.
WriteFile
(
filepath
.
Join
(
dir
,
"file"
),
[]
byte
(
fileContent
),
0600
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
dummyUpstream
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
dummyUpstream
.
handleServeFile
(
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
helper
.
AssertResponseCode
(
t
,
w
,
200
)
helper
.
AssertResponseCode
(
t
,
w
,
200
)
if
enableGzip
{
if
enableGzip
{
helper
.
AssertResponseHeader
(
t
,
w
,
"Content-Encoding"
,
"gzip"
)
helper
.
AssertResponseHeader
(
t
,
w
,
"Content-Encoding"
,
"gzip"
)
...
...
upstream.go
View file @
1559a5f7
...
@@ -24,6 +24,7 @@ import (
...
@@ -24,6 +24,7 @@ import (
type
upstream
struct
{
type
upstream
struct
{
API
*
api
.
API
API
*
api
.
API
Proxy
*
proxy
.
Proxy
Proxy
*
proxy
.
Proxy
DocumentRoot
string
authBackend
string
authBackend
string
relativeURLRoot
string
relativeURLRoot
string
routes
[]
route
routes
[]
route
...
@@ -79,10 +80,10 @@ func (u *upstream) compileRoutes() {
...
@@ -79,10 +80,10 @@ func (u *upstream) compileRoutes() {
// Serve assets
// Serve assets
route
{
""
,
regexp
.
MustCompile
(
`^/assets/`
),
route
{
""
,
regexp
.
MustCompile
(
`^/assets/`
),
u
.
handleServeFile
(
d
ocumentRoot
,
CacheExpireMax
,
u
.
handleServeFile
(
u
.
D
ocumentRoot
,
CacheExpireMax
,
handleDevelopmentMode
(
developmentMode
,
handleDevelopmentMode
(
developmentMode
,
handleDeployPage
(
d
ocumentRoot
,
handleDeployPage
(
u
.
D
ocumentRoot
,
errorpage
.
Inject
(
*
d
ocumentRoot
,
errorpage
.
Inject
(
u
.
D
ocumentRoot
,
u
.
Proxy
,
u
.
Proxy
,
),
),
),
),
...
@@ -92,9 +93,9 @@ func (u *upstream) compileRoutes() {
...
@@ -92,9 +93,9 @@ func (u *upstream) compileRoutes() {
// Serve static files or forward the requests
// Serve static files or forward the requests
route
{
""
,
nil
,
route
{
""
,
nil
,
u
.
handleServeFile
(
d
ocumentRoot
,
CacheDisabled
,
u
.
handleServeFile
(
u
.
D
ocumentRoot
,
CacheDisabled
,
handleDeployPage
(
d
ocumentRoot
,
handleDeployPage
(
u
.
D
ocumentRoot
,
errorpage
.
Inject
(
*
d
ocumentRoot
,
errorpage
.
Inject
(
u
.
D
ocumentRoot
,
u
.
Proxy
,
u
.
Proxy
,
),
),
),
),
...
...
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