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
94b19e8c
Commit
94b19e8c
authored
Nov 04, 2015
by
Marin Jankovski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add option for sending callback for handlers.
parent
fa7eaedc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
14 deletions
+53
-14
archive.go
archive.go
+3
-1
git-http.go
git-http.go
+6
-2
githandler.go
githandler.go
+40
-8
lfs.go
lfs.go
+4
-3
No files found.
archive.go
View file @
94b19e8c
...
@@ -16,7 +16,7 @@ import (
...
@@ -16,7 +16,7 @@ import (
"time"
"time"
)
)
func
handleGetArchive
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
format
string
)
{
func
handleGetArchive
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
format
string
)
(
callback
*
gitRequest
)
{
archiveFilename
:=
path
.
Base
(
r
.
ArchivePath
)
archiveFilename
:=
path
.
Base
(
r
.
ArchivePath
)
if
cachedArchive
,
err
:=
os
.
Open
(
r
.
ArchivePath
);
err
==
nil
{
if
cachedArchive
,
err
:=
os
.
Open
(
r
.
ArchivePath
);
err
==
nil
{
...
@@ -103,6 +103,8 @@ func handleGetArchive(w http.ResponseWriter, r *gitRequest, format string) {
...
@@ -103,6 +103,8 @@ func handleGetArchive(w http.ResponseWriter, r *gitRequest, format string) {
logContext
(
"handleGetArchive finalize cached archive"
,
err
)
logContext
(
"handleGetArchive finalize cached archive"
,
err
)
return
return
}
}
return
}
}
func
setArchiveHeaders
(
w
http
.
ResponseWriter
,
format
string
,
archiveFilename
string
)
{
func
setArchiveHeaders
(
w
http
.
ResponseWriter
,
format
string
,
archiveFilename
string
)
{
...
...
git-http.go
View file @
94b19e8c
...
@@ -12,7 +12,7 @@ import (
...
@@ -12,7 +12,7 @@ import (
"strings"
"strings"
)
)
func
handleGetInfoRefs
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
_
string
)
{
func
handleGetInfoRefs
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
_
string
)
(
callback
*
gitRequest
)
{
rpc
:=
r
.
URL
.
Query
()
.
Get
(
"service"
)
rpc
:=
r
.
URL
.
Query
()
.
Get
(
"service"
)
if
!
(
rpc
==
"git-upload-pack"
||
rpc
==
"git-receive-pack"
)
{
if
!
(
rpc
==
"git-upload-pack"
||
rpc
==
"git-receive-pack"
)
{
// The 'dumb' Git HTTP protocol is not supported
// The 'dumb' Git HTTP protocol is not supported
...
@@ -54,9 +54,11 @@ func handleGetInfoRefs(w http.ResponseWriter, r *gitRequest, _ string) {
...
@@ -54,9 +54,11 @@ func handleGetInfoRefs(w http.ResponseWriter, r *gitRequest, _ string) {
logContext
(
"handleGetInfoRefs wait for subprocess"
,
err
)
logContext
(
"handleGetInfoRefs wait for subprocess"
,
err
)
return
return
}
}
return
}
}
func
handlePostRPC
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
rpc
string
)
{
func
handlePostRPC
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
rpc
string
)
(
callback
*
gitRequest
)
{
var
body
io
.
ReadCloser
var
body
io
.
ReadCloser
var
err
error
var
err
error
...
@@ -121,6 +123,8 @@ func handlePostRPC(w http.ResponseWriter, r *gitRequest, rpc string) {
...
@@ -121,6 +123,8 @@ func handlePostRPC(w http.ResponseWriter, r *gitRequest, rpc string) {
logContext
(
"handlePostRPC wait for subprocess"
,
err
)
logContext
(
"handlePostRPC wait for subprocess"
,
err
)
return
return
}
}
return
}
}
func
subCommand
(
rpc
string
)
string
{
func
subCommand
(
rpc
string
)
string
{
...
...
githandler.go
View file @
94b19e8c
...
@@ -25,7 +25,7 @@ type gitHandler struct {
...
@@ -25,7 +25,7 @@ type gitHandler struct {
type
gitService
struct
{
type
gitService
struct
{
method
string
method
string
regex
*
regexp
.
Regexp
regex
*
regexp
.
Regexp
handleFunc
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
rpc
string
)
handleFunc
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
rpc
string
)
(
*
gitRequest
)
rpc
string
rpc
string
}
}
...
@@ -144,7 +144,17 @@ func (h *gitHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
...
@@ -144,7 +144,17 @@ func (h *gitHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
return
}
}
g
.
handleFunc
(
w
,
gitReq
,
g
.
rpc
)
callback
:=
g
.
handleFunc
(
w
,
gitReq
,
g
.
rpc
)
if
callback
==
nil
{
return
}
h
.
doCallback
(
w
,
callback
)
// _, err := h.doCallback(w, callback)
// h.doCallback(w, callback)
// if err != nil
// return nil, err
// }
}
}
func
looksLikeRepo
(
p
string
)
bool
{
func
looksLikeRepo
(
p
string
)
bool
{
...
@@ -159,21 +169,43 @@ func looksLikeRepo(p string) bool {
...
@@ -159,21 +169,43 @@ func looksLikeRepo(p string) bool {
func
(
h
*
gitHandler
)
doAuthRequest
(
r
*
http
.
Request
)
(
result
*
http
.
Response
,
err
error
)
{
func
(
h
*
gitHandler
)
doAuthRequest
(
r
*
http
.
Request
)
(
result
*
http
.
Response
,
err
error
)
{
url
:=
h
.
authBackend
+
r
.
URL
.
RequestURI
()
url
:=
h
.
authBackend
+
r
.
URL
.
RequestURI
()
authReq
,
err
:=
http
.
NewRequest
(
r
.
Method
,
url
,
nil
)
authReq
:=
doRequest
(
r
,
url
)
if
authReq
!=
nil
{
return
h
.
httpClient
.
Do
(
authReq
)
}
return
}
func
(
h
*
gitHandler
)
doCallback
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
(
result
*
http
.
Response
,
err
error
)
{
url
:=
h
.
authBackend
+
r
.
URL
.
RequestURI
()
+
"/callback"
callbackReq
:=
doRequest
(
r
,
url
)
if
callbackReq
!=
nil
{
return
h
.
httpClient
.
Do
(
callbackReq
)
}
return
}
func
doRequest
(
r
*
gitRequest
,
url
string
)
(
request
*
http
.
Request
)
{
request
,
err
:=
http
.
NewRequest
(
r
.
Method
,
url
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
}
}
// Forward all headers from our client to the auth backend. This includes
// Forward all headers from our client to the auth backend. This includes
// HTTP Basic authentication credentials (the 'Authorization' header).
// HTTP Basic authentication credentials (the 'Authorization' header).
for
k
,
v
:=
range
r
.
Header
{
for
k
,
v
:=
range
r
.
Header
{
authReq
.
Header
[
k
]
=
v
request
.
Header
[
k
]
=
v
}
}
// Also forward the Host header, which is excluded from the Header map by the http libary.
// Also forward the Host header, which is excluded from the Header map by the http libary.
// This allows the Host header received by the backend to be consistent with other
// This allows the Host header received by the backend to be consistent with other
// requests not going through gitlab-workhorse.
// requests not going through gitlab-workhorse.
authReq
.
Host
=
r
.
Host
request
.
Host
=
r
.
Host
// Set a custom header for the request. This can be used in some
// Set a custom header for the request. This can be used in some
// configurations (Passenger) to solve auth request routing problems.
// configurations (Passenger) to solve auth request routing problems.
authReq
.
Header
.
Set
(
"GitLab-Git-HTTP-Server"
,
Version
)
request
.
Header
.
Set
(
"GitLab-Git-HTTP-Server"
,
Version
)
return
h
.
httpClient
.
Do
(
authReq
)
return
request
}
}
lfs.go
View file @
94b19e8c
...
@@ -23,7 +23,7 @@ var (
...
@@ -23,7 +23,7 @@ var (
errSizeMismatch
=
errors
.
New
(
"Content size does not match"
)
errSizeMismatch
=
errors
.
New
(
"Content size does not match"
)
)
)
func
handleStoreLfsObject
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
rpc
string
)
{
func
handleStoreLfsObject
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
rpc
string
)
(
callback
*
gitRequest
)
{
var
body
io
.
ReadCloser
var
body
io
.
ReadCloser
var
err
error
var
err
error
...
@@ -106,10 +106,11 @@ func handleStoreLfsObject(w http.ResponseWriter, r *gitRequest, rpc string) {
...
@@ -106,10 +106,11 @@ func handleStoreLfsObject(w http.ResponseWriter, r *gitRequest, rpc string) {
log
.
Printf
(
"Received the LFS object from client, oid: %s"
,
oid
)
log
.
Printf
(
"Received the LFS object from client, oid: %s"
,
oid
)
return
return
r
}
}
func
handleRetreiveLfsObject
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
rpc
string
)
{
func
handleRetreiveLfsObject
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
rpc
string
)
(
callback
*
gitRequest
)
{
log
.
Printf
(
"I should download %s"
,
r
)
log
.
Printf
(
"I should download %s"
,
r
)
urlPath
:=
r
.
URL
.
Path
urlPath
:=
r
.
URL
.
Path
...
...
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