mirror of
https://github.com/caddyserver/caddy.git
synced 2025-10-19 07:43:17 +00:00
Implement most of static file server; refactor and improve Replacer
This commit is contained in:
parent
1a20fe330e
commit
fec7fa8bfd
14 changed files with 991 additions and 255 deletions
|
@ -23,16 +23,16 @@ type Static struct {
|
|||
}
|
||||
|
||||
func (s Static) ServeHTTP(w http.ResponseWriter, r *http.Request) error {
|
||||
repl := r.Context().Value(ReplacerCtxKey).(*Replacer)
|
||||
repl := r.Context().Value(caddy2.ReplacerCtxKey).(caddy2.Replacer)
|
||||
|
||||
// close the connection after responding
|
||||
r.Close = s.Close
|
||||
|
||||
// set all headers, with replacements
|
||||
for field, vals := range s.Headers {
|
||||
field = repl.Replace(field, "")
|
||||
field = repl.ReplaceAll(field, "")
|
||||
for i := range vals {
|
||||
vals[i] = repl.Replace(vals[i], "")
|
||||
vals[i] = repl.ReplaceAll(vals[i], "")
|
||||
}
|
||||
w.Header()[field] = vals
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ func (s Static) ServeHTTP(w http.ResponseWriter, r *http.Request) error {
|
|||
|
||||
// write the response body, with replacements
|
||||
if s.Body != "" {
|
||||
fmt.Fprint(w, repl.Replace(s.Body, ""))
|
||||
fmt.Fprint(w, repl.ReplaceAll(s.Body, ""))
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue