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