Commit fb1df36e authored by Jacob Vosmaer's avatar Jacob Vosmaer

More http.Handler, less http.HandlerFunc

parent 14d70b3b
......@@ -28,7 +28,7 @@ func runPreAuthorizeHandler(t *testing.T, suffix string, url *regexp.Regexp, api
a := &api.API{URL: helper.URLMustParse(ts.URL), Version: "123"}
response := httptest.NewRecorder()
a.PreAuthorizeHandler(okHandler, suffix)(response, httpRequest)
a.PreAuthorizeHandler(okHandler, suffix).ServeHTTP(response, httpRequest)
helper.AssertResponseCode(t, response, expectedCode)
return response
}
......
......@@ -105,8 +105,8 @@ func (api *API) newRequest(r *http.Request, body io.Reader, suffix string) (*htt
return authReq, nil
}
func (api *API) PreAuthorizeHandler(h HandleFunc, suffix string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
func (api *API) PreAuthorizeHandler(h HandleFunc, suffix string) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
authReq, err := api.newRequest(r, nil, suffix)
if err != nil {
helper.Fail500(w, fmt.Errorf("preAuthorizeHandler: newUpstreamRequest: %v", err))
......@@ -160,5 +160,5 @@ func (api *API) PreAuthorizeHandler(h HandleFunc, suffix string) http.HandlerFun
}
h(w, r, a)
}
})
}
......@@ -36,7 +36,7 @@ func looksLikeRepo(p string) bool {
return true
}
func repoPreAuthorizeHandler(myAPI *api.API, handleFunc api.HandleFunc) http.HandlerFunc {
func repoPreAuthorizeHandler(myAPI *api.API, handleFunc api.HandleFunc) http.Handler {
return myAPI.PreAuthorizeHandler(func(w http.ResponseWriter, r *http.Request, a *api.Response) {
if a.RepoPath == "" {
helper.Fail500(w, errors.New("repoPreAuthorizeHandler: RepoPath empty"))
......
......@@ -20,11 +20,11 @@ import (
"path/filepath"
)
func PutStore(a *api.API, p *proxy.Proxy) http.HandlerFunc {
func PutStore(a *api.API, p *proxy.Proxy) http.Handler {
return lfsAuthorizeHandler(a, handleStoreLfsObject(p))
}
func lfsAuthorizeHandler(myAPI *api.API, handleFunc api.HandleFunc) http.HandlerFunc {
func lfsAuthorizeHandler(myAPI *api.API, handleFunc api.HandleFunc) http.Handler {
return myAPI.PreAuthorizeHandler(func(w http.ResponseWriter, r *http.Request, a *api.Response) {
if a.StoreLFSPath == "" {
......
......@@ -86,8 +86,8 @@ func rewriteFormFilesFromMultipart(r *http.Request, writer *multipart.Writer, te
return cleanup, nil
}
func handleFileUploads(h http.Handler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
func handleFileUploads(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
tempPath := r.Header.Get(tempPathHeader)
if tempPath == "" {
helper.Fail500(w, errors.New("handleFileUploads: TempPath empty"))
......@@ -124,5 +124,5 @@ func handleFileUploads(h http.Handler) http.HandlerFunc {
// Proxy the request
h.ServeHTTP(w, r)
}
})
}
......@@ -8,8 +8,8 @@ import (
"net/http"
)
func contentEncodingHandler(h http.Handler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
func contentEncodingHandler(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var body io.ReadCloser
var err error
......@@ -34,5 +34,5 @@ func contentEncodingHandler(h http.Handler) http.HandlerFunc {
r.Header.Del("Content-Encoding")
h.ServeHTTP(w, r)
}
})
}
......@@ -35,7 +35,7 @@ func TestGzipEncoding(t *testing.T) {
if r.Header.Get("Content-Encoding") != "" {
t.Fatal("Content-Encoding should be deleted")
}
}))(resp, req)
})).ServeHTTP(resp, req)
helper.AssertResponseCode(t, resp, 200)
}
......@@ -59,7 +59,7 @@ func TestNoEncoding(t *testing.T) {
if r.Header.Get("Content-Encoding") != "" {
t.Fatal("Content-Encoding should be deleted")
}
}))(resp, req)
})).ServeHTTP(resp, req)
helper.AssertResponseCode(t, resp, 200)
}
......@@ -75,7 +75,7 @@ func TestInvalidEncoding(t *testing.T) {
contentEncodingHandler(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
t.Fatal("it shouldn't be executed")
}))(resp, req)
})).ServeHTTP(resp, req)
helper.AssertResponseCode(t, resp, 500)
}
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