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
257952ff
Commit
257952ff
authored
Dec 19, 2015
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename 'handleDevelopmentMode' to 'NotFoundUnless'
parent
61e4d00c
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
27 additions
and
30 deletions
+27
-30
internal/upstream/development.go
internal/upstream/development.go
+0
-14
internal/upstream/development_test.go
internal/upstream/development_test.go
+4
-4
internal/upstream/notfoundunless.go
internal/upstream/notfoundunless.go
+11
-0
internal/upstream/routes.go
internal/upstream/routes.go
+1
-1
internal/upstream/servefile.go
internal/upstream/servefile.go
+4
-4
internal/upstream/servefile_test.go
internal/upstream/servefile_test.go
+7
-7
No files found.
internal/upstream/development.go
deleted
100644 → 0
View file @
61e4d00c
package
upstream
import
"net/http"
func
handleDevelopmentMode
(
developmentMode
bool
,
handler
http
.
HandlerFunc
)
http
.
HandlerFunc
{
return
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
!
developmentMode
{
http
.
NotFound
(
w
,
r
)
return
}
handler
(
w
,
r
)
}
}
internal/upstream/development_test.go
View file @
257952ff
...
...
@@ -14,9 +14,9 @@ func TestDevelopmentModeEnabled(t *testing.T) {
w
:=
httptest
.
NewRecorder
()
executed
:=
false
handleDevelopmentMode
(
developmentMode
,
func
(
_
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
NotFoundUnless
(
developmentMode
,
http
.
HandlerFunc
(
func
(
_
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
executed
=
true
})(
w
,
r
)
})
)
.
ServeHTTP
(
w
,
r
)
if
!
executed
{
t
.
Error
(
"The handler should get executed"
)
}
...
...
@@ -29,9 +29,9 @@ func TestDevelopmentModeDisabled(t *testing.T) {
w
:=
httptest
.
NewRecorder
()
executed
:=
false
handleDevelopmentMode
(
developmentMode
,
func
(
_
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
NotFoundUnless
(
developmentMode
,
http
.
HandlerFunc
(
func
(
_
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
executed
=
true
})(
w
,
r
)
})
)
.
ServeHTTP
(
w
,
r
)
if
executed
{
t
.
Error
(
"The handler should not get executed"
)
}
...
...
internal/upstream/notfoundunless.go
0 → 100644
View file @
257952ff
package
upstream
import
"net/http"
func
NotFoundUnless
(
pass
bool
,
handler
http
.
Handler
)
http
.
Handler
{
if
pass
{
return
handler
}
else
{
return
http
.
HandlerFunc
(
http
.
NotFound
)
}
}
internal/upstream/routes.go
View file @
257952ff
...
...
@@ -64,7 +64,7 @@ func (u *Upstream) configureRoutes() {
// Serve assets
route
{
""
,
regexp
.
MustCompile
(
`^/assets/`
),
handleServeFile
(
u
.
DocumentRoot
,
u
.
URLPrefix
(),
CacheExpireMax
,
handleDevelopmentMode
(
u
.
DevelopmentMode
,
NotFoundUnless
(
u
.
DevelopmentMode
,
handleDeployPage
(
u
.
DocumentRoot
,
errorpage
.
Inject
(
u
.
DocumentRoot
,
u
.
Proxy
(),
...
...
internal/upstream/servefile.go
View file @
257952ff
...
...
@@ -17,8 +17,8 @@ const (
CacheExpireMax
)
func
handleServeFile
(
documentRoot
string
,
prefix
urlPrefix
,
cache
CacheMode
,
notFoundHandler
http
.
Handler
Func
)
http
.
HandlerFunc
{
return
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
handleServeFile
(
documentRoot
string
,
prefix
urlPrefix
,
cache
CacheMode
,
notFoundHandler
http
.
Handler
)
http
.
Handler
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
file
:=
filepath
.
Join
(
documentRoot
,
prefix
.
strip
(
r
.
URL
.
Path
))
// The filepath.Join does Clean traversing directories up
...
...
@@ -49,7 +49,7 @@ func handleServeFile(documentRoot string, prefix urlPrefix, cache CacheMode, not
}
if
err
!=
nil
{
if
notFoundHandler
!=
nil
{
notFoundHandler
(
w
,
r
)
notFoundHandler
.
ServeHTTP
(
w
,
r
)
}
else
{
http
.
NotFound
(
w
,
r
)
}
...
...
@@ -67,5 +67,5 @@ func handleServeFile(documentRoot string, prefix urlPrefix, cache CacheMode, not
log
.
Printf
(
"Send static file %q (%q) for %s %q"
,
file
,
w
.
Header
()
.
Get
(
"Content-Encoding"
),
r
.
Method
,
r
.
RequestURI
)
http
.
ServeContent
(
w
,
r
,
filepath
.
Base
(
file
),
fi
.
ModTime
(),
content
)
}
}
)
}
internal/upstream/servefile_test.go
View file @
257952ff
...
...
@@ -17,7 +17,7 @@ func TestServingNonExistingFile(t *testing.T) {
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/file"
,
nil
)
w
:=
httptest
.
NewRecorder
()
handleServeFile
(
dir
,
"/"
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
handleServeFile
(
dir
,
"/"
,
CacheDisabled
,
nil
)
.
ServeHTTP
(
w
,
httpRequest
)
helper
.
AssertResponseCode
(
t
,
w
,
404
)
}
...
...
@@ -30,7 +30,7 @@ func TestServingDirectory(t *testing.T) {
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/file"
,
nil
)
w
:=
httptest
.
NewRecorder
()
handleServeFile
(
dir
,
"/"
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
handleServeFile
(
dir
,
"/"
,
CacheDisabled
,
nil
)
.
ServeHTTP
(
w
,
httpRequest
)
helper
.
AssertResponseCode
(
t
,
w
,
404
)
}
...
...
@@ -39,7 +39,7 @@ func TestServingMalformedUri(t *testing.T) {
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/../../../static/file"
,
nil
)
w
:=
httptest
.
NewRecorder
()
handleServeFile
(
dir
,
"/"
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
handleServeFile
(
dir
,
"/"
,
CacheDisabled
,
nil
)
.
ServeHTTP
(
w
,
httpRequest
)
helper
.
AssertResponseCode
(
t
,
w
,
404
)
}
...
...
@@ -48,9 +48,9 @@ func TestExecutingHandlerWhenNoFileFound(t *testing.T) {
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/file"
,
nil
)
executed
:=
false
handleServeFile
(
dir
,
"/"
,
CacheDisabled
,
func
(
_
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
handleServeFile
(
dir
,
"/"
,
CacheDisabled
,
http
.
HandlerFunc
(
func
(
_
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
executed
=
(
r
==
httpRequest
)
})(
nil
,
httpRequest
)
})
)
.
ServeHTTP
(
nil
,
httpRequest
)
if
!
executed
{
t
.
Error
(
"The handler should get executed"
)
}
...
...
@@ -69,7 +69,7 @@ func TestServingTheActualFile(t *testing.T) {
ioutil
.
WriteFile
(
filepath
.
Join
(
dir
,
"file"
),
[]
byte
(
fileContent
),
0600
)
w
:=
httptest
.
NewRecorder
()
handleServeFile
(
dir
,
"/"
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
handleServeFile
(
dir
,
"/"
,
CacheDisabled
,
nil
)
.
ServeHTTP
(
w
,
httpRequest
)
helper
.
AssertResponseCode
(
t
,
w
,
200
)
if
w
.
Body
.
String
()
!=
fileContent
{
t
.
Error
(
"We should serve the file: "
,
w
.
Body
.
String
())
...
...
@@ -100,7 +100,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
,
httpRequest
)
handleServeFile
(
dir
,
"/"
,
CacheDisabled
,
nil
)
.
ServeHTTP
(
w
,
httpRequest
)
helper
.
AssertResponseCode
(
t
,
w
,
200
)
if
enableGzip
{
helper
.
AssertResponseHeader
(
t
,
w
,
"Content-Encoding"
,
"gzip"
)
...
...
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