From 7669c5b5ec5b18e96a0714d667468247a3da3d68 Mon Sep 17 00:00:00 2001 From: nolash Date: Thu, 26 Jan 2017 20:33:39 +0100 Subject: cmd/swarm, swarm/api: bzzr improve + networkid prio fixes #3444 fixes #3494 networkid override Added comments to explain why test against 0 appears twice * Command line overrides saved config, saved config overrides system default --- fixes #3476 bzzr get with path Finally a hopefully clean commit for this PR Added check for empty path to avoid SIGSEGV in path parser and resolver Added requested tests for empty path and non-existing manifest. However signature for StartHTTPServer had changed. Now it's hacked as so: StartHttpServer(api.API, &Server{Addr: "127.0.0.1:8504", CorsString: ""}) * Parse url before resolve when path and ENS is supplied, example * swarm/api/http proxy server test for retrieval of subpath through get * Removed nil entry assignment on subtrie leaf in recursive key retrieval * Cleaned up path-or-no-path condition in proxy server get handler * swarm: processed with gofmt refers to lash/go-ethereum@90daa7a * swarm: Added public access method Parse alias to parse * swarm: processed with gofmt References nolash/go-ethereum@2ec3fd7 * Rename parse to Parse, removed alias --- swarm/api/http/server.go | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'swarm/api/http/server.go') 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 { -- cgit