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

Method do

modules/caddyhttp/rewrite/rewrite.go:465–485  ·  view source on GitHub ↗

do performs the substring replacement on r.

(r *http.Request, repl *caddy.Replacer)

Source from the content-addressed store, hash-verified

463
464// do performs the substring replacement on r.
465func (rep substrReplacer) do(r *http.Request, repl *caddy.Replacer) {
466 if rep.Find == "" {
467 return
468 }
469
470 lim := rep.Limit
471 if lim == 0 {
472 lim = -1
473 }
474
475 find := repl.ReplaceAll(rep.Find, "")
476 replace := repl.ReplaceAll(rep.Replace, "")
477
478 mergeSlashes := !strings.Contains(rep.Find, "//")
479
480 changePath(r, func(pathOrRawPath string) string {
481 return strings.Replace(caddyhttp.CleanPath(pathOrRawPath, mergeSlashes), find, replace, lim)
482 })
483
484 r.URL.RawQuery = strings.Replace(r.URL.RawQuery, find, replace, lim)
485}
486
487// regexReplacer describes a replacement using a regular expression.
488type regexReplacer struct {

Callers

nothing calls this directly

Calls 3

CleanPathFunction · 0.92
changePathFunction · 0.85
ReplaceAllMethod · 0.80

Tested by

no test coverage detected