Commit 94b19e8c authored by Marin Jankovski's avatar Marin Jankovski

Add option for sending callback for handlers.

parent fa7eaedc
......@@ -16,7 +16,7 @@ import (
"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)
if cachedArchive, err := os.Open(r.ArchivePath); err == nil {
......@@ -103,6 +103,8 @@ func handleGetArchive(w http.ResponseWriter, r *gitRequest, format string) {
logContext("handleGetArchive finalize cached archive", err)
return
}
return
}
func setArchiveHeaders(w http.ResponseWriter, format string, archiveFilename string) {
......
......@@ -12,7 +12,7 @@ import (
"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")
if !(rpc == "git-upload-pack" || rpc == "git-receive-pack") {
// The 'dumb' Git HTTP protocol is not supported
......@@ -54,9 +54,11 @@ func handleGetInfoRefs(w http.ResponseWriter, r *gitRequest, _ string) {
logContext("handleGetInfoRefs wait for subprocess", err)
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 err error
......@@ -121,6 +123,8 @@ func handlePostRPC(w http.ResponseWriter, r *gitRequest, rpc string) {
logContext("handlePostRPC wait for subprocess", err)
return
}
return
}
func subCommand(rpc string) string {
......
......@@ -25,7 +25,7 @@ type gitHandler struct {
type gitService struct {
method string
regex *regexp.Regexp
handleFunc func(w http.ResponseWriter, r *gitRequest, rpc string)
handleFunc func(w http.ResponseWriter, r *gitRequest, rpc string)(*gitRequest)
rpc string
}
......@@ -144,7 +144,17 @@ func (h *gitHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
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 {
......@@ -159,21 +169,43 @@ func looksLikeRepo(p string) bool {
func (h *gitHandler) doAuthRequest(r *http.Request) (result *http.Response, err error) {
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 {
return nil, err
return nil
}
// Forward all headers from our client to the auth backend. This includes
// HTTP Basic authentication credentials (the 'Authorization' 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.
// This allows the Host header received by the backend to be consistent with other
// 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
// configurations (Passenger) to solve auth request routing problems.
authReq.Header.Set("GitLab-Git-HTTP-Server", Version)
return h.httpClient.Do(authReq)
request.Header.Set("GitLab-Git-HTTP-Server", Version)
return request
}
......@@ -23,7 +23,7 @@ var (
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 err error
......@@ -106,10 +106,11 @@ func handleStoreLfsObject(w http.ResponseWriter, r *gitRequest, rpc string) {
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)
urlPath := r.URL.Path
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment