core/corehttp: Added handling of /ipns/<hash>/x paths
Matt Bell committed
Jan 27, 2015 at 00:54 UTC
2759d1c1263f0428c016c4e04c3f1cd2d475c753
1 file changed
+8
-6
core/corehttp/gateway_handler.go
+8
-6
@@ -66,9 +66,12 @@ func (i *gatewayHandler) loadTemplate() error {
66
}
67
68
func (i *gatewayHandler) ResolvePath(ctx context.Context, p string) (*dag.Node, string, error) {
69
+ p = path.Clean(p)
70
+
71
if strings.HasPrefix(p, "/ipns/") {
70
- elements := strings.Split(path.Clean(p[6:]), "/")
71
- k, err := i.node.Namesys.Resolve(ctx, elements[0])
72
+ elements := strings.Split(p[6:], "/")
73
+ hash := elements[0]
74
+ k, err := i.node.Namesys.Resolve(ctx, hash)
75
if err != nil {
76
return nil, "", err
77
}
@@ -169,16 +172,15 @@ func (i *gatewayHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
172
break
173
}
174
172
- di := directoryItem{link.Size, link.Name, path.Join(p, link.Name)}
175
+ di := directoryItem{link.Size, link.Name, path.Join(urlPath, link.Name)}
176
dirListing = append(dirListing, di)
177
}
178
179
if !foundIndex {
180
// template and return directory listing
181
hndlr := webHandler{
179
- "listing": dirListing,
180
- "path": urlPath,
181
- "actualPath": p,
182
+ "listing": dirListing,
183
+ "path": urlPath,
184
}
185
if err := i.dirList.Execute(w, hndlr); err != nil {
186
internalWebError(w, err)