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:
@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user