MCPcopy
hub / github.com/caddyserver/caddy / ServeHTTP

Method ServeHTTP

modules/caddyhttp/rewrite/rewrite.go:132–153  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler)

Source from the content-addressed store, hash-verified

130}
131
132func (rewr Rewrite) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error {
133 repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
134 const message = "rewrote request"
135
136 c := rewr.logger.Check(zap.DebugLevel, message)
137 if c == nil {
138 rewr.Rewrite(r, repl)
139 return next.ServeHTTP(w, r)
140 }
141
142 changed := rewr.Rewrite(r, repl)
143
144 if changed {
145 c.Write(
146 zap.Object("request", caddyhttp.LoggableHTTPRequest{Request: r}),
147 zap.String("method", r.Method),
148 zap.String("uri", r.RequestURI),
149 )
150 }
151
152 return next.ServeHTTP(w, r)
153}
154
155// rewrite performs the rewrites on r using repl, which should
156// have been obtained from r, but is passed in for efficiency.

Callers

nothing calls this directly

Calls 6

RewriteMethod · 0.95
ServeHTTPMethod · 0.65
ValueMethod · 0.45
CheckMethod · 0.45
WriteMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected