aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAron Fischer <github@aron.guru>2016-12-22 07:35:05 +0800
committerFelix Lange <fjl@users.noreply.github.com>2016-12-22 07:35:05 +0800
commit9a51f5c3506ed644e4e24f879cbb1ae7098f6dbc (patch)
tree927572fbe53d8803f5baae91cfa60f4914dce03d
parent301c0a6303d62ebe9b022736d816abe20924f63f (diff)
downloadgo-tangerine-9a51f5c3506ed644e4e24f879cbb1ae7098f6dbc.tar
go-tangerine-9a51f5c3506ed644e4e24f879cbb1ae7098f6dbc.tar.gz
go-tangerine-9a51f5c3506ed644e4e24f879cbb1ae7098f6dbc.tar.bz2
go-tangerine-9a51f5c3506ed644e4e24f879cbb1ae7098f6dbc.tar.lz
go-tangerine-9a51f5c3506ed644e4e24f879cbb1ae7098f6dbc.tar.xz
go-tangerine-9a51f5c3506ed644e4e24f879cbb1ae7098f6dbc.tar.zst
go-tangerine-9a51f5c3506ed644e4e24f879cbb1ae7098f6dbc.zip
swarm/http: check error returned by reader.Size (#3470)
-rw-r--r--swarm/api/http/server.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/swarm/api/http/server.go b/swarm/api/http/server.go
index 9be60ef94..f82775f25 100644
--- a/swarm/api/http/server.go
+++ b/swarm/api/http/server.go
@@ -99,7 +99,7 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) {
"[BZZ] Swarm: Protocol error in request `%s`.",
uri,
)
- http.Error(w, "BZZ protocol error", http.StatusBadRequest)
+ http.Error(w, "Invalid request URL: need access protocol (bzz:/, bzzr:/, bzzi:/) as first element in path.", http.StatusBadRequest)
return
}
}
@@ -187,6 +187,12 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) {
reader := a.Retrieve(key)
quitC := make(chan bool)
size, err := reader.Size(quitC)
+ if err != nil {
+ glog.V(logger.Debug).Infof("Could not determine size: %v", err.Error())
+ //An error on call to Size means we don't have the root chunk
+ http.Error(w, err.Error(), http.StatusNotFound)
+ return
+ }
glog.V(logger.Debug).Infof("Reading %d bytes.", size)
// setting mime type
@@ -229,6 +235,12 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) {
}
quitC := make(chan bool)
size, err := reader.Size(quitC)
+ if err != nil {
+ glog.V(logger.Debug).Infof("Could not determine size: %v", err.Error())
+ //An error on call to Size means we don't have the root chunk
+ http.Error(w, err.Error(), http.StatusNotFound)
+ return
+ }
glog.V(logger.Debug).Infof("Served '%s' (%d bytes) as '%s' (status code: %v)", uri, size, mimeType, status)
http.ServeContent(w, r, path, forever(), reader)