@cryptotaxi247 / kubo / commits / e2be5c203

core/corehttp: Added RedirectOption

Matt Bell committed Jan 26, 2015 at 23:03 UTC e2be5c2039f87ca2517d6a43ac217f23682315c2
2 files changed +26 -22
core/corehttp/redirect.go new
+23
@@ -0,0 +1,23 @@
1 +package corehttp
2 +
3 +import (
4 + "net/http"
5 +
6 + core "github.com/jbenet/go-ipfs/core"
7 +)
8 +
9 +func RedirectOption(path string, redirect string) ServeOption {
10 + handler := &redirectHandler{redirect}
11 + return func(n *core.IpfsNode, mux *http.ServeMux) error {
12 + mux.Handle("/"+path, handler)
13 + return nil
14 + }
15 +}
16 +
17 +type redirectHandler struct {
18 + path string
19 +}
20 +
21 +func (i *redirectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
22 + http.Redirect(w, r, i.path, 302)
23 +}
core/corehttp/webui.go
+3 -22
@@ -1,25 +1,6 @@
1 package corehttp
2
3 -import (
4 - "net/http"
3 +// TODO: move to IPNS
4 +const webuiPath = "/ipfs/QmctngrQAt9fjpQUZr7Bx3BsXUcif52eZGTizWhvcShsjz"
5
6 - core "github.com/jbenet/go-ipfs/core"
7 -)
8 -
9 -const (
10 - // TODO rename
11 - webuiPath = "/ipfs/QmTWvqK9dYvqjAMAcCeUun8b45Fwu7wPhEN9B9TsGbkXfJ"
12 -)
13 -
14 -func WebUIOption(n *core.IpfsNode, mux *http.ServeMux) error {
15 - mux.Handle("/webui/", &redirectHandler{webuiPath})
16 - return nil
17 -}
18 -
19 -type redirectHandler struct {
20 - path string
21 -}
22 -
23 -func (i *redirectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
24 - http.Redirect(w, r, i.path, 302)
25 -}
6 +var WebUIOption = RedirectOption("webui", webuiPath)