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.go32
1 files changed, 25 insertions, 7 deletions
diff --git a/swarm/api/http/server.go b/swarm/api/http/server.go
index c8e79ab4e..afd867efc 100644
--- a/swarm/api/http/server.go
+++ b/swarm/api/http/server.go
@@ -32,6 +32,7 @@ import (
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/swarm/api"
+ "github.com/ethereum/go-ethereum/swarm/storage"
"github.com/rs/cors"
)
@@ -194,17 +195,34 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) {
}
case r.Method == "GET" || r.Method == "HEAD":
path = trailingSlashes.ReplaceAllString(path, "")
+ if path == "" {
+ http.Error(w, "Empty path not allowed", http.StatusBadRequest)
+ return
+ }
if raw {
- // resolving host
- key, err := a.Resolve(path, nameresolver)
- if err != nil {
- glog.V(logger.Error).Infof("%v", err)
- http.Error(w, err.Error(), http.StatusBadRequest)
- return
+ var reader storage.LazySectionReader
+ parsedurl, _ := api.Parse(path)
+
+ if parsedurl == path {
+ key, err := a.Resolve(parsedurl, nameresolver)
+ if err != nil {
+ glog.V(logger.Error).Infof("%v", err)
+ http.Error(w, err.Error(), http.StatusBadRequest)
+ return
+ }
+ reader = a.Retrieve(key)
+ } else {
+ var status int
+ readertmp, _, status, err := a.Get(path, nameresolver)
+ if err != nil {
+ http.Error(w, err.Error(), status)
+ return
+ }
+ reader = readertmp
}
// retrieving content
- reader := a.Retrieve(key)
+
quitC := make(chan bool)
size, err := reader.Size(quitC)
if err != nil {