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
362c1385
Commit
362c1385
authored
Dec 11, 2015
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added development mode and serve assets with cache enabled
parent
ac409d67
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
0 deletions
+72
-0
development.go
development.go
+14
-0
development_test.go
development_test.go
+38
-0
helpers_test.go
helpers_test.go
+6
-0
main.go
main.go
+14
-0
No files found.
development.go
0 → 100644
View file @
362c1385
package
main
import
"net/http"
func
handleDevelopmentMode
(
developmentMode
*
bool
,
handler
serviceHandleFunc
)
serviceHandleFunc
{
return
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
if
!*
developmentMode
{
http
.
NotFound
(
w
,
r
.
Request
)
return
}
handler
(
w
,
r
)
}
}
development_test.go
0 → 100644
View file @
362c1385
package
main
import
(
"net/http"
"net/http/httptest"
"testing"
)
func
TestDevelopmentModeEnabled
(
t
*
testing
.
T
)
{
developmentMode
:=
true
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/something"
,
nil
)
w
:=
httptest
.
NewRecorder
()
executed
:=
false
handleDevelopmentMode
(
&
developmentMode
,
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
executed
=
true
})(
w
,
&
gitRequest
{
Request
:
r
})
if
!
executed
{
t
.
Error
(
"The handler should get executed"
)
}
}
func
TestDevelopmentModeDisabled
(
t
*
testing
.
T
)
{
developmentMode
:=
false
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/something"
,
nil
)
w
:=
httptest
.
NewRecorder
()
executed
:=
false
handleDevelopmentMode
(
&
developmentMode
,
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
executed
=
true
})(
w
,
&
gitRequest
{
Request
:
r
})
if
executed
{
t
.
Error
(
"The handler should not get executed"
)
}
assertResponseCode
(
t
,
w
,
404
)
}
helpers_test.go
View file @
362c1385
...
...
@@ -16,3 +16,9 @@ func assertResponseBody(t *testing.T, response *httptest.ResponseRecorder, expec
t
.
Fatalf
(
"for HTTP request expected to receive %q, got %q instead as body"
,
expectedBody
,
response
.
Body
.
String
())
}
}
func
assertResponseHeader
(
t
*
testing
.
T
,
response
*
httptest
.
ResponseRecorder
,
header
string
,
expectedValue
string
)
{
if
response
.
Header
()
.
Get
(
header
)
!=
expectedValue
{
t
.
Fatalf
(
"for HTTP request expected to receive the header %q with %q, got %q"
,
header
,
expectedValue
,
response
.
Header
()
.
Get
(
header
))
}
}
main.go
View file @
362c1385
...
...
@@ -39,6 +39,7 @@ var pprofListenAddr = flag.String("pprofListenAddr", "", "pprof listening addres
var
relativeURLRoot
=
flag
.
String
(
"relativeURLRoot"
,
"/"
,
"GitLab relative URL root"
)
var
documentRoot
=
flag
.
String
(
"documentRoot"
,
"public"
,
"Path to static files content"
)
var
responseHeadersTimeout
=
flag
.
Duration
(
"proxyHeadersTimeout"
,
time
.
Minute
,
"How long to wait for response headers when proxying the request"
)
var
developmentMode
=
flag
.
Bool
(
"developmentMode"
,
false
,
"Allow to serve assets from Rails app"
)
type
httpRoute
struct
{
method
string
...
...
@@ -85,6 +86,19 @@ var httpRoutes = [...]httpRoute{
httpRoute
{
""
,
regexp
.
MustCompile
(
apiPattern
),
proxyRequest
},
httpRoute
{
""
,
regexp
.
MustCompile
(
ciAPIPattern
),
proxyRequest
},
// Serve assets
httpRoute
{
""
,
regexp
.
MustCompile
(
`^/assets/`
),
handleServeFile
(
documentRoot
,
CacheExpireMax
,
handleDevelopmentMode
(
developmentMode
,
handleDeployPage
(
documentRoot
,
handleRailsError
(
documentRoot
,
proxyRequest
,
),
),
),
),
},
// Serve static files or forward the requests
httpRoute
{
""
,
nil
,
handleServeFile
(
documentRoot
,
CacheDisabled
,
...
...
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