1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-08-11 17:50:58 +00:00

fix cache proxy to work properly

This commit is contained in:
Kwonunn 2024-11-09 16:56:20 +01:00 committed by Kwonunn
parent 4b5ffd768f
commit 975364553b

View file

@ -71,9 +71,12 @@ func StartHandler(repoName string, targetHost string, outboundIP string, port ui
}
router := httprouter.New()
router.HandlerFunc("GET", urlBase, proxyRequestHandler(proxy))
router.HandlerFunc("POST", urlBase, proxyRequestHandler(proxy))
router.HandlerFunc("PATCH", urlBase, proxyRequestHandler(proxy))
router.HandlerFunc("GET", urlBase+"/cache", proxyRequestHandler(proxy))
router.HandlerFunc("POST", urlBase+"/caches", proxyRequestHandler(proxy))
router.HandlerFunc("PATCH", urlBase+"/caches/:id", proxyRequestHandler(proxy))
router.HandlerFunc("POST", urlBase+"/caches/:id", proxyRequestHandler(proxy))
router.HandlerFunc("GET", urlBase+"/artifacts/:id", proxyRequestHandler(proxy))
router.HandlerFunc("POST", urlBase+"/clean", proxyRequestHandler(proxy))
h.router = router
@ -108,8 +111,13 @@ func (h *Handler) newReverseProxy(targetHost string) (*httputil.ReverseProxy, er
return nil, err
}
proxy := httputil.NewSingleHostReverseProxy(url)
proxy.Rewrite = func(r *httputil.ProxyRequest) { h.injectAuth(r) }
proxy := &httputil.ReverseProxy{
Rewrite: func(r *httputil.ProxyRequest) {
r.SetURL(url)
r.Out.Host = r.In.Host // if desired
h.injectAuth(r)
},
}
return proxy, nil
}