Response to cors preflight checks before the upstream log gets configured
@@ -148,6 +148,12 @@ func NewProxy(options *ProxyOptions, log *logrus.Entry, evalCtx *hcl.EvalContext
}
func (p *Proxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
+ if p.options.CORS != nil && isCorsPreflightRequest(req) {
+ p.setCorsRespHeaders(rw.Header(), req)
+ rw.WriteHeader(http.StatusNoContent)
+ return
+ }
+
*req = *req.Clone(context.WithValue(req.Context(), request.BackendName, p.options.BackendName))
p.upstreamLog.ServeHTTP(rw, req, logging.RoundtripHandlerFunc(p.roundtrip))
}
@@ -161,12 +167,6 @@ func (p *Proxy) roundtrip(rw http.ResponseWriter, req *http.Request) {
defer cancelFn()
}
- if p.options.CORS != nil && isCorsPreflightRequest(req) {
- p.setCorsRespHeaders(rw.Header(), req)
- rw.WriteHeader(http.StatusNoContent)
- return
- }
-
outreq := req.Clone(ctx)
if req.ContentLength == 0 {
outreq.Body = nil // Issue 16036: nil Body for http.Transport retries
