aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/api/http/server.go
diff options
context:
space:
mode:
Diffstat (limited to 'swarm/api/http/server.go')
-rw-r--r--swarm/api/http/server.go66
1 files changed, 43 insertions, 23 deletions
diff --git a/swarm/api/http/server.go b/swarm/api/http/server.go
index a637b8735..65f6afab7 100644
--- a/swarm/api/http/server.go
+++ b/swarm/api/http/server.go
@@ -441,14 +441,37 @@ func (s *Server) HandleGetList(w http.ResponseWriter, r *Request) {
return
}
- walker, err := s.api.NewManifestWalker(key, nil)
+ list, err := s.getManifestList(key, r.uri.Path)
+
if err != nil {
s.Error(w, r, err)
return
}
- var list api.ManifestList
- prefix := r.uri.Path
+ // if the client wants HTML (e.g. a browser) then render the list as a
+ // HTML index with relative URLs
+ if strings.Contains(r.Header.Get("Accept"), "text/html") {
+ w.Header().Set("Content-Type", "text/html")
+ err := htmlListTemplate.Execute(w, &htmlListData{
+ URI: r.uri,
+ List: &list,
+ })
+ if err != nil {
+ s.logError("error rendering list HTML: %s", err)
+ }
+ return
+ }
+
+ w.Header().Set("Content-Type", "application/json")
+ json.NewEncoder(w).Encode(&list)
+}
+
+func (s *Server) getManifestList(key storage.Key, prefix string) (list api.ManifestList, err error) {
+ walker, err := s.api.NewManifestWalker(key, nil)
+ if err != nil {
+ return
+ }
+
err = walker.Walk(func(entry *api.ManifestEntry) error {
// handle non-manifest files
if entry.ContentType != api.ManifestType {
@@ -495,27 +518,8 @@ func (s *Server) HandleGetList(w http.ResponseWriter, r *Request) {
// so just skip it
return api.SkipManifest
})
- if err != nil {
- s.Error(w, r, err)
- return
- }
- // if the client wants HTML (e.g. a browser) then render the list as a
- // HTML index with relative URLs
- if strings.Contains(r.Header.Get("Accept"), "text/html") {
- w.Header().Set("Content-Type", "text/html")
- err := htmlListTemplate.Execute(w, &htmlListData{
- URI: r.uri,
- List: &list,
- })
- if err != nil {
- s.logError("error rendering list HTML: %s", err)
- }
- return
- }
-
- w.Header().Set("Content-Type", "application/json")
- json.NewEncoder(w).Encode(&list)
+ return list, nil
}
// HandleGetFile handles a GET request to bzz://<manifest>/<path> and responds
@@ -544,6 +548,22 @@ func (s *Server) HandleGetFile(w http.ResponseWriter, r *Request) {
return
}
+ //the request results in ambiguous files
+ //e.g. /read with readme.md and readinglist.txt available in manifest
+ if status == http.StatusMultipleChoices {
+ list, err := s.getManifestList(key, r.uri.Path)
+
+ if err != nil {
+ s.Error(w, r, err)
+ return
+ }
+
+ s.logDebug(fmt.Sprintf("Multiple choices! --> %v", list))
+ //show a nice page links to available entries
+ ShowMultipleChoices(w, &r.Request, list)
+ return
+ }
+
// check the root chunk exists by retrieving the file's size
if _, err := reader.Size(nil); err != nil {
s.NotFound(w, r, fmt.Errorf("File not found %s: %s", r.uri, err))