1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-05-17 15:06:47 +08:00

fix: apply API.HTTPHeaders to /webui redirect

This commit is contained in:
Henrique Dias
2023-03-17 15:14:10 +01:00
committed by GitHub
parent 23b5abfb7a
commit 63b2a0e069
2 changed files with 30 additions and 2 deletions

View File

@ -8,8 +8,14 @@ import (
)
func RedirectOption(path string, redirect string) ServeOption {
handler := &redirectHandler{redirect}
return func(n *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {
cfg, err := n.Repo.Config()
if err != nil {
return nil, err
}
handler := &redirectHandler{redirect, cfg.API.HTTPHeaders}
if len(path) > 0 {
mux.Handle("/"+path+"/", handler)
} else {
@ -20,9 +26,14 @@ func RedirectOption(path string, redirect string) ServeOption {
}
type redirectHandler struct {
path string
path string
headers map[string][]string
}
func (i *redirectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
for k, v := range i.headers {
w.Header()[k] = v
}
http.Redirect(w, r, i.path, http.StatusFound)
}