aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/api/http/server.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-01-30 22:36:30 +0800
committerGitHub <noreply@github.com>2017-01-30 22:36:30 +0800
commit1c140f73820e2a915dcc61eccaeca7ea359cf07b (patch)
treeed3c5330a14344d6c716d19306154f17cd1efcbc /swarm/api/http/server.go
parentf3c368ca736ed2884943cf87b029d305b7fc7c61 (diff)
parente5a93bf99abc0db5efbfab17feb61cfaef5a19ed (diff)
downloaddexon-1c140f73820e2a915dcc61eccaeca7ea359cf07b.tar
dexon-1c140f73820e2a915dcc61eccaeca7ea359cf07b.tar.gz
dexon-1c140f73820e2a915dcc61eccaeca7ea359cf07b.tar.bz2
dexon-1c140f73820e2a915dcc61eccaeca7ea359cf07b.tar.lz
dexon-1c140f73820e2a915dcc61eccaeca7ea359cf07b.tar.xz
dexon-1c140f73820e2a915dcc61eccaeca7ea359cf07b.tar.zst
dexon-1c140f73820e2a915dcc61eccaeca7ea359cf07b.zip
Merge pull request #3615 from nolash/bzzpathfix_real5
cmd/swarm, swarm/api: bzzr improve + networkid prio
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 {