Parse url before resolve when path and ENS is supplied, example for illustration

This commit is contained in:
nolash 2017-01-02 14:27:40 +01:00
parent 662b8f69ad
commit 922f1055a4

View file

@ -31,6 +31,7 @@ import (
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog" "github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/swarm/api" "github.com/ethereum/go-ethereum/swarm/api"
"github.com/ethereum/go-ethereum/swarm/storage"
) )
const ( const (
@ -175,16 +176,40 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) {
case r.Method == "GET" || r.Method == "HEAD": case r.Method == "GET" || r.Method == "HEAD":
path = trailingSlashes.ReplaceAllString(path, "") path = trailingSlashes.ReplaceAllString(path, "")
if raw { if raw {
var reader storage.LazySectionReader
//
parsedurl, _ := api.Parse(path)
//if err != nil {
//
//}
// resolving host // resolving host
key, err := a.Resolve(path, nameresolver) if (parsedurl == path) {
if err != nil { key, err := a.Resolve(parsedurl, nameresolver)
glog.V(logger.Error).Infof("%v", err) if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest) glog.V(logger.Error).Infof("%v", err)
return http.Error(w, err.Error(), http.StatusBadRequest)
return
}
reader = a.Retrieve(key)
} else {
readertmp, _, status, err := a.Get(path, nameresolver)
reader = readertmp
if err != nil {
if _, ok := err.(api.ErrResolve); ok {
glog.V(logger.Debug).Infof("%v", err)
status = http.StatusBadRequest
} else {
glog.V(logger.Debug).Infof("error retrieving '%s': %v", uri, err)
status = http.StatusNotFound
}
http.Error(w, err.Error(), status)
return
}
} }
// retrieving content // retrieving content
reader := a.Retrieve(key)
quitC := make(chan bool) quitC := make(chan bool)
size, err := reader.Size(quitC) size, err := reader.Size(quitC)
if err != nil { if err != nil {