SwarmProxyPortFlag back in utils/flags.go eth Config; fix httpaccess uri slash trimming

This commit is contained in:
zelig 2015-05-27 10:20:35 +01:00
parent 14d90eee7c
commit 9788ed5337
3 changed files with 9 additions and 6 deletions

View file

@ -89,7 +89,7 @@ func (self *Api) resolveHost(hostport string) (contentHash Key, errR errResolve)
var host, port string var host, port string
var err error var err error
host, port, err = net.SplitHostPort(hostport) host, port, err = net.SplitHostPort(hostport)
if err != nil { if err != nil && err.Error() != "missing port in address "+hostport {
errR = errResolve(fmt.Errorf("invalid host '%s': %v", hostport, err)) errR = errResolve(fmt.Errorf("invalid host '%s': %v", hostport, err))
return return
} }

View file

@ -37,14 +37,16 @@ func startHttpServer(api *Api, port string) {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
handler(w, r, api) handler(w, r, api)
}) })
go http.ListenAndServe(port, nil) go http.ListenAndServe(":"+port, nil)
dpaLogger.Infof("Swarm HTTP proxy started.") dpaLogger.Infof("Swarm HTTP proxy started on localhost:%s", port)
} }
func handler(w http.ResponseWriter, r *http.Request, api *Api) { func handler(w http.ResponseWriter, r *http.Request, api *Api) {
dpaLogger.Debugf("request URL: '%s' Host: '%s', Path: '%s'", r.RequestURI, r.URL.Host, r.URL.Path)
switch { switch {
case r.Method == "POST": case r.Method == "POST":
dpaLogger.Debugf("request URL Host: '%s', Path: '%s'", r.URL.Host, r.URL.Path)
if r.URL.Path == "/raw" { if r.URL.Path == "/raw" {
dpaLogger.Debugf("Swarm: POST request received.") dpaLogger.Debugf("Swarm: POST request received.")
key, err := api.dpa.Store(io.NewSectionReader(&sequentialReader{ key, err := api.dpa.Store(io.NewSectionReader(&sequentialReader{
@ -53,7 +55,7 @@ func handler(w http.ResponseWriter, r *http.Request, api *Api) {
}, 0, r.ContentLength), nil) }, 0, r.ContentLength), nil)
if err == nil { if err == nil {
fmt.Fprintf(w, "%064x", key) fmt.Fprintf(w, "%064x", key)
dpaLogger.Debugf("Swarm: Object %064x stored", key) dpaLogger.Debugf("Swarm: Content for '%064x' stored", key)
} else { } else {
http.Error(w, err.Error(), http.StatusBadRequest) http.Error(w, err.Error(), http.StatusBadRequest)
return return
@ -72,7 +74,7 @@ func handler(w http.ResponseWriter, r *http.Request, api *Api) {
// resolving host // resolving host
name := uri[5:] name := uri[5:]
key, err := api.resolveHost(uri) key, err := api.resolveHost(name)
if err != nil { if err != nil {
dpaLogger.Debugf("Swarm: %v", err) dpaLogger.Debugf("Swarm: %v", err)
http.Error(w, err.Error(), http.StatusBadRequest) http.Error(w, err.Error(), http.StatusBadRequest)
@ -100,7 +102,7 @@ func handler(w http.ResponseWriter, r *http.Request, api *Api) {
dpaLogger.Debugf("Swarm: Structured GET request '%s' received.", uri) dpaLogger.Debugf("Swarm: Structured GET request '%s' received.", uri)
// call to api.getPath on uri // call to api.getPath on uri
reader, mimeType, status, err := api.getPath(uri) reader, mimeType, status, err := api.getPath(uri[1:])
if err != nil { if err != nil {
var status int var status int
if _, ok := err.(errResolve); ok { if _, ok := err.(errResolve); ok {

View file

@ -329,6 +329,7 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
NodeKey: GetNodeKey(ctx), NodeKey: GetNodeKey(ctx),
Shh: ctx.GlobalBool(WhisperEnabledFlag.Name), Shh: ctx.GlobalBool(WhisperEnabledFlag.Name),
Bzz: ctx.GlobalBool(SwarmEnabledFlag.Name), Bzz: ctx.GlobalBool(SwarmEnabledFlag.Name),
BzzPort: ctx.GlobalString(SwarmProxyPortFlag.Name),
Dial: true, Dial: true,
BootNodes: ctx.GlobalString(BootnodesFlag.Name), BootNodes: ctx.GlobalString(BootnodesFlag.Name),
GasPrice: common.String2Big(ctx.GlobalString(GasPriceFlag.Name)), GasPrice: common.String2Big(ctx.GlobalString(GasPriceFlag.Name)),