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
Kazuhiko Shiozaki
gitlab-workhorse
Commits
3dd96bd4
Commit
3dd96bd4
authored
Dec 18, 2015
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More ServeHTTP and detach methods from API
parent
34fa7497
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
61 additions
and
59 deletions
+61
-59
artifacts.go
artifacts.go
+1
-1
error_pages.go
error_pages.go
+2
-2
error_pages_test.go
error_pages_test.go
+6
-6
git-http.go
git-http.go
+1
-1
lfs.go
lfs.go
+34
-32
main.go
main.go
+17
-17
No files found.
artifacts.go
View file @
3dd96bd4
...
@@ -4,7 +4,7 @@ import (
...
@@ -4,7 +4,7 @@ import (
"net/http"
"net/http"
)
)
func
(
api
*
API
)
artifactsAuthorizeHandler
(
h
httpHandleFunc
)
httpHandleFunc
{
func
artifactsAuthorizeHandler
(
api
*
API
,
h
httpHandleFunc
)
httpHandleFunc
{
return
api
.
preAuthorizeHandler
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
apiResponse
)
{
return
api
.
preAuthorizeHandler
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
apiResponse
)
{
r
.
Header
.
Set
(
tempPathHeader
,
a
.
TempPath
)
r
.
Header
.
Set
(
tempPathHeader
,
a
.
TempPath
)
h
(
w
,
r
)
h
(
w
,
r
)
...
...
error_pages.go
View file @
3dd96bd4
...
@@ -59,13 +59,13 @@ func (s *errorPageResponseWriter) Flush() {
...
@@ -59,13 +59,13 @@ func (s *errorPageResponseWriter) Flush() {
s
.
WriteHeader
(
http
.
StatusOK
)
s
.
WriteHeader
(
http
.
StatusOK
)
}
}
func
handleRailsError
(
documentRoot
*
string
,
handler
http
HandleFunc
)
httpHandleFunc
{
func
handleRailsError
(
documentRoot
*
string
,
handler
http
.
Handler
)
httpHandleFunc
{
return
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
return
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
rw
:=
errorPageResponseWriter
{
rw
:=
errorPageResponseWriter
{
rw
:
w
,
rw
:
w
,
path
:
documentRoot
,
path
:
documentRoot
,
}
}
defer
rw
.
Flush
()
defer
rw
.
Flush
()
handler
(
&
rw
,
r
)
handler
.
ServeHTTP
(
&
rw
,
r
)
}
}
}
}
error_pages_test.go
View file @
3dd96bd4
...
@@ -21,11 +21,11 @@ func TestIfErrorPageIsPresented(t *testing.T) {
...
@@ -21,11 +21,11 @@ func TestIfErrorPageIsPresented(t *testing.T) {
ioutil
.
WriteFile
(
filepath
.
Join
(
dir
,
"404.html"
),
[]
byte
(
errorPage
),
0600
)
ioutil
.
WriteFile
(
filepath
.
Join
(
dir
,
"404.html"
),
[]
byte
(
errorPage
),
0600
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
h
:=
httpHandleFunc
(
func
(
w
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
handleRailsError
(
&
dir
,
func
(
w
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
w
.
WriteHeader
(
404
)
w
.
WriteHeader
(
404
)
fmt
.
Fprint
(
w
,
"Not Found"
)
fmt
.
Fprint
(
w
,
"Not Found"
)
})(
w
,
nil
)
})
handleRailsError
(
&
dir
,
h
)(
w
,
nil
)
w
.
Flush
()
w
.
Flush
()
assertResponseCode
(
t
,
w
,
404
)
assertResponseCode
(
t
,
w
,
404
)
...
@@ -41,11 +41,11 @@ func TestIfErrorPassedIfNoErrorPageIsFound(t *testing.T) {
...
@@ -41,11 +41,11 @@ func TestIfErrorPassedIfNoErrorPageIsFound(t *testing.T) {
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
errorResponse
:=
"ERROR"
errorResponse
:=
"ERROR"
h
:=
httpHandleFunc
(
func
(
w
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
handleRailsError
(
&
dir
,
func
(
w
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
w
.
WriteHeader
(
404
)
w
.
WriteHeader
(
404
)
fmt
.
Fprint
(
w
,
errorResponse
)
fmt
.
Fprint
(
w
,
errorResponse
)
})(
w
,
nil
)
})
handleRailsError
(
&
dir
,
h
)(
w
,
nil
)
w
.
Flush
()
w
.
Flush
()
assertResponseCode
(
t
,
w
,
404
)
assertResponseCode
(
t
,
w
,
404
)
...
...
git-http.go
View file @
3dd96bd4
...
@@ -26,7 +26,7 @@ func looksLikeRepo(p string) bool {
...
@@ -26,7 +26,7 @@ func looksLikeRepo(p string) bool {
return
true
return
true
}
}
func
(
api
*
API
)
repoPreAuthorizeHandler
(
handleFunc
serviceHandleFunc
)
httpHandleFunc
{
func
repoPreAuthorizeHandler
(
api
*
API
,
handleFunc
serviceHandleFunc
)
httpHandleFunc
{
return
api
.
preAuthorizeHandler
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
apiResponse
)
{
return
api
.
preAuthorizeHandler
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
apiResponse
)
{
if
a
.
RepoPath
==
""
{
if
a
.
RepoPath
==
""
{
fail500
(
w
,
errors
.
New
(
"repoPreAuthorizeHandler: RepoPath empty"
))
fail500
(
w
,
errors
.
New
(
"repoPreAuthorizeHandler: RepoPath empty"
))
...
...
lfs.go
View file @
3dd96bd4
...
@@ -17,7 +17,7 @@ import (
...
@@ -17,7 +17,7 @@ import (
"path/filepath"
"path/filepath"
)
)
func
(
api
*
API
)
lfsAuthorizeHandler
(
handleFunc
serviceHandleFunc
)
httpHandleFunc
{
func
lfsAuthorizeHandler
(
api
*
API
,
handleFunc
serviceHandleFunc
)
httpHandleFunc
{
return
api
.
preAuthorizeHandler
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
apiResponse
)
{
return
api
.
preAuthorizeHandler
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
apiResponse
)
{
if
a
.
StoreLFSPath
==
""
{
if
a
.
StoreLFSPath
==
""
{
...
@@ -39,7 +39,8 @@ func (api *API) lfsAuthorizeHandler(handleFunc serviceHandleFunc) httpHandleFunc
...
@@ -39,7 +39,8 @@ func (api *API) lfsAuthorizeHandler(handleFunc serviceHandleFunc) httpHandleFunc
},
"/authorize"
)
},
"/authorize"
)
}
}
func
(
p
*
Proxy
)
handleStoreLfsObject
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
apiResponse
)
{
func
handleStoreLfsObject
(
h
http
.
Handler
)
serviceHandleFunc
{
return
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
apiResponse
)
{
file
,
err
:=
ioutil
.
TempFile
(
a
.
StoreLFSPath
,
a
.
LfsOid
)
file
,
err
:=
ioutil
.
TempFile
(
a
.
StoreLFSPath
,
a
.
LfsOid
)
if
err
!=
nil
{
if
err
!=
nil
{
fail500
(
w
,
fmt
.
Errorf
(
"handleStoreLfsObject: create tempfile: %v"
,
err
))
fail500
(
w
,
fmt
.
Errorf
(
"handleStoreLfsObject: create tempfile: %v"
,
err
))
...
@@ -75,5 +76,6 @@ func (p *Proxy) handleStoreLfsObject(w http.ResponseWriter, r *http.Request, a *
...
@@ -75,5 +76,6 @@ func (p *Proxy) handleStoreLfsObject(w http.ResponseWriter, r *http.Request, a *
r
.
ContentLength
=
0
r
.
ContentLength
=
0
// And proxy the request
// And proxy the request
p
.
ServeHTTP
(
w
,
r
)
h
.
ServeHTTP
(
w
,
r
)
}
}
}
main.go
View file @
3dd96bd4
...
@@ -70,27 +70,27 @@ func compileRoutes(u *upstream) {
...
@@ -70,27 +70,27 @@ func compileRoutes(u *upstream) {
proxy
:=
u
.
Proxy
proxy
:=
u
.
Proxy
httpRoutes
=
[]
httpRoute
{
httpRoutes
=
[]
httpRoute
{
// Git Clone
// Git Clone
httpRoute
{
"GET"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`info/refs\z`
),
api
.
repoPreAuthorizeHandler
(
handleGetInfoRefs
)},
httpRoute
{
"GET"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`info/refs\z`
),
repoPreAuthorizeHandler
(
api
,
handleGetInfoRefs
)},
httpRoute
{
"POST"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`git-upload-pack\z`
),
contentEncodingHandler
(
api
.
repoPreAuthorizeHandler
(
handlePostRPC
))},
httpRoute
{
"POST"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`git-upload-pack\z`
),
contentEncodingHandler
(
repoPreAuthorizeHandler
(
api
,
handlePostRPC
))},
httpRoute
{
"POST"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`git-receive-pack\z`
),
contentEncodingHandler
(
api
.
repoPreAuthorizeHandler
(
handlePostRPC
))},
httpRoute
{
"POST"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`git-receive-pack\z`
),
contentEncodingHandler
(
repoPreAuthorizeHandler
(
api
,
handlePostRPC
))},
httpRoute
{
"PUT"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`gitlab-lfs/objects/([0-9a-f]{64})/([0-9]+)\z`
),
api
.
lfsAuthorizeHandler
(
proxy
.
handleStoreLfsObject
)},
httpRoute
{
"PUT"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`gitlab-lfs/objects/([0-9a-f]{64})/([0-9]+)\z`
),
lfsAuthorizeHandler
(
api
,
handleStoreLfsObject
(
proxy
)
)},
// Repository Archive
// Repository Archive
httpRoute
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive\z`
),
api
.
repoPreAuthorizeHandler
(
handleGetArchive
)},
httpRoute
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive\z`
),
repoPreAuthorizeHandler
(
api
,
handleGetArchive
)},
httpRoute
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.zip\z`
),
api
.
repoPreAuthorizeHandler
(
handleGetArchive
)},
httpRoute
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.zip\z`
),
repoPreAuthorizeHandler
(
api
,
handleGetArchive
)},
httpRoute
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.tar\z`
),
api
.
repoPreAuthorizeHandler
(
handleGetArchive
)},
httpRoute
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.tar\z`
),
repoPreAuthorizeHandler
(
api
,
handleGetArchive
)},
httpRoute
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.tar.gz\z`
),
api
.
repoPreAuthorizeHandler
(
handleGetArchive
)},
httpRoute
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.tar.gz\z`
),
repoPreAuthorizeHandler
(
api
,
handleGetArchive
)},
httpRoute
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.tar.bz2\z`
),
api
.
repoPreAuthorizeHandler
(
handleGetArchive
)},
httpRoute
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.tar.bz2\z`
),
repoPreAuthorizeHandler
(
api
,
handleGetArchive
)},
// Repository Archive API
// Repository Archive API
httpRoute
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive\z`
),
api
.
repoPreAuthorizeHandler
(
handleGetArchive
)},
httpRoute
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive\z`
),
repoPreAuthorizeHandler
(
api
,
handleGetArchive
)},
httpRoute
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.zip\z`
),
api
.
repoPreAuthorizeHandler
(
handleGetArchive
)},
httpRoute
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.zip\z`
),
repoPreAuthorizeHandler
(
api
,
handleGetArchive
)},
httpRoute
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.tar\z`
),
api
.
repoPreAuthorizeHandler
(
handleGetArchive
)},
httpRoute
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.tar\z`
),
repoPreAuthorizeHandler
(
api
,
handleGetArchive
)},
httpRoute
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.tar.gz\z`
),
api
.
repoPreAuthorizeHandler
(
handleGetArchive
)},
httpRoute
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.tar.gz\z`
),
repoPreAuthorizeHandler
(
api
,
handleGetArchive
)},
httpRoute
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.tar.bz2\z`
),
api
.
repoPreAuthorizeHandler
(
handleGetArchive
)},
httpRoute
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.tar.bz2\z`
),
repoPreAuthorizeHandler
(
api
,
handleGetArchive
)},
// CI Artifacts API
// CI Artifacts API
httpRoute
{
"POST"
,
regexp
.
MustCompile
(
ciAPIPattern
+
`v1/builds/[0-9]+/artifacts\z`
),
contentEncodingHandler
(
a
pi
.
artifactsAuthorizeHandler
(
handleFileUploads
(
proxy
)))},
httpRoute
{
"POST"
,
regexp
.
MustCompile
(
ciAPIPattern
+
`v1/builds/[0-9]+/artifacts\z`
),
contentEncodingHandler
(
a
rtifactsAuthorizeHandler
(
api
,
handleFileUploads
(
proxy
)))},
// Explicitly proxy API requests
// Explicitly proxy API requests
httpRoute
{
""
,
regexp
.
MustCompile
(
apiPattern
),
proxy
},
httpRoute
{
""
,
regexp
.
MustCompile
(
apiPattern
),
proxy
},
...
@@ -102,7 +102,7 @@ func compileRoutes(u *upstream) {
...
@@ -102,7 +102,7 @@ func compileRoutes(u *upstream) {
handleDevelopmentMode
(
developmentMode
,
handleDevelopmentMode
(
developmentMode
,
handleDeployPage
(
documentRoot
,
handleDeployPage
(
documentRoot
,
handleRailsError
(
documentRoot
,
handleRailsError
(
documentRoot
,
proxy
.
ServeHTTP
,
proxy
,
),
),
),
),
),
),
...
@@ -114,7 +114,7 @@ func compileRoutes(u *upstream) {
...
@@ -114,7 +114,7 @@ func compileRoutes(u *upstream) {
u
.
handleServeFile
(
documentRoot
,
CacheDisabled
,
u
.
handleServeFile
(
documentRoot
,
CacheDisabled
,
handleDeployPage
(
documentRoot
,
handleDeployPage
(
documentRoot
,
handleRailsError
(
documentRoot
,
handleRailsError
(
documentRoot
,
proxy
.
ServeHTTP
,
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