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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
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 (
"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
)
{
deployPage
:=
filepath
.
Join
(
*
documentRoot
,
"index.html"
)
deployPage
:=
filepath
.
Join
(
documentRoot
,
"index.html"
)
data
,
err
:=
ioutil
.
ReadFile
(
deployPage
)
if
err
!=
nil
{
handler
.
ServeHTTP
(
w
,
r
)
...
...
deploy_page_test.go
View file @
1559a5f7
...
...
@@ -20,7 +20,7 @@ func TestIfNoDeployPageExist(t *testing.T) {
w
:=
httptest
.
NewRecorder
()
executed
:=
false
handleDeployPage
(
&
dir
,
http
.
HandlerFunc
(
func
(
_
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
handleDeployPage
(
dir
,
http
.
HandlerFunc
(
func
(
_
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
executed
=
true
}))(
w
,
nil
)
if
!
executed
{
...
...
@@ -41,7 +41,7 @@ func TestIfDeployPageExist(t *testing.T) {
w
:=
httptest
.
NewRecorder
()
executed
:=
false
handleDeployPage
(
&
dir
,
http
.
HandlerFunc
(
func
(
_
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
handleDeployPage
(
dir
,
http
.
HandlerFunc
(
func
(
_
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
executed
=
true
}))(
w
,
nil
)
if
executed
{
...
...
main.go
View file @
1559a5f7
...
...
@@ -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 (
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
)
{
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
if
!
strings
.
HasPrefix
(
file
,
*
documentRoot
)
{
if
!
strings
.
HasPrefix
(
file
,
documentRoot
)
{
helper
.
Fail500
(
w
,
&
os
.
PathError
{
Op
:
"open"
,
Path
:
file
,
...
...
servefile_test.go
View file @
1559a5f7
...
...
@@ -19,7 +19,7 @@ func TestServingNonExistingFile(t *testing.T) {
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/file"
,
nil
)
w
:=
httptest
.
NewRecorder
()
dummyUpstream
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
dummyUpstream
.
handleServeFile
(
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
helper
.
AssertResponseCode
(
t
,
w
,
404
)
}
...
...
@@ -32,7 +32,7 @@ func TestServingDirectory(t *testing.T) {
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/file"
,
nil
)
w
:=
httptest
.
NewRecorder
()
dummyUpstream
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
dummyUpstream
.
handleServeFile
(
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
helper
.
AssertResponseCode
(
t
,
w
,
404
)
}
...
...
@@ -41,7 +41,7 @@ func TestServingMalformedUri(t *testing.T) {
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/../../../static/file"
,
nil
)
w
:=
httptest
.
NewRecorder
()
dummyUpstream
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
dummyUpstream
.
handleServeFile
(
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
helper
.
AssertResponseCode
(
t
,
w
,
404
)
}
...
...
@@ -50,7 +50,7 @@ func TestExecutingHandlerWhenNoFileFound(t *testing.T) {
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/file"
,
nil
)
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
)
})(
nil
,
httpRequest
)
if
!
executed
{
...
...
@@ -71,7 +71,7 @@ func TestServingTheActualFile(t *testing.T) {
ioutil
.
WriteFile
(
filepath
.
Join
(
dir
,
"file"
),
[]
byte
(
fileContent
),
0600
)
w
:=
httptest
.
NewRecorder
()
dummyUpstream
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
dummyUpstream
.
handleServeFile
(
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
helper
.
AssertResponseCode
(
t
,
w
,
200
)
if
w
.
Body
.
String
()
!=
fileContent
{
t
.
Error
(
"We should serve the file: "
,
w
.
Body
.
String
())
...
...
@@ -102,7 +102,7 @@ func testServingThePregzippedFile(t *testing.T, enableGzip bool) {
ioutil
.
WriteFile
(
filepath
.
Join
(
dir
,
"file"
),
[]
byte
(
fileContent
),
0600
)
w
:=
httptest
.
NewRecorder
()
dummyUpstream
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
dummyUpstream
.
handleServeFile
(
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
helper
.
AssertResponseCode
(
t
,
w
,
200
)
if
enableGzip
{
helper
.
AssertResponseHeader
(
t
,
w
,
"Content-Encoding"
,
"gzip"
)
...
...
upstream.go
View file @
1559a5f7
...
...
@@ -24,6 +24,7 @@ import (
type
upstream
struct
{
API
*
api
.
API
Proxy
*
proxy
.
Proxy
DocumentRoot
string
authBackend
string
relativeURLRoot
string
routes
[]
route
...
...
@@ -79,10 +80,10 @@ func (u *upstream) compileRoutes() {
// Serve assets
route
{
""
,
regexp
.
MustCompile
(
`^/assets/`
),
u
.
handleServeFile
(
d
ocumentRoot
,
CacheExpireMax
,
u
.
handleServeFile
(
u
.
D
ocumentRoot
,
CacheExpireMax
,
handleDevelopmentMode
(
developmentMode
,
handleDeployPage
(
d
ocumentRoot
,
errorpage
.
Inject
(
*
d
ocumentRoot
,
handleDeployPage
(
u
.
D
ocumentRoot
,
errorpage
.
Inject
(
u
.
D
ocumentRoot
,
u
.
Proxy
,
),
),
...
...
@@ -92,9 +93,9 @@ func (u *upstream) compileRoutes() {
// Serve static files or forward the requests
route
{
""
,
nil
,
u
.
handleServeFile
(
d
ocumentRoot
,
CacheDisabled
,
handleDeployPage
(
d
ocumentRoot
,
errorpage
.
Inject
(
*
d
ocumentRoot
,
u
.
handleServeFile
(
u
.
D
ocumentRoot
,
CacheDisabled
,
handleDeployPage
(
u
.
D
ocumentRoot
,
errorpage
.
Inject
(
u
.
D
ocumentRoot
,
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