mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
p2p/simulations: support GET requests with query string in URL
This commit is contained in:
parent
20e91384bf
commit
9fc8097768
2 changed files with 19 additions and 4 deletions
|
|
@ -2,6 +2,8 @@ package simulations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -72,7 +74,13 @@ func handle(w http.ResponseWriter, r *http.Request, c Controller) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// on return we close the request Body so we assume it is read synchronously
|
// on return we close the request Body so we assume it is read synchronously
|
||||||
response, err := handler(r.Body)
|
var params io.ReadCloser
|
||||||
|
if r.Method == "GET" && len(r.URL.RawQuery) > 0 {
|
||||||
|
params = ioutil.NopCloser(strings.NewReader(r.URL.RawQuery))
|
||||||
|
} else {
|
||||||
|
params = r.Body
|
||||||
|
}
|
||||||
|
response, err := handler(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, fmt.Sprintf("handler error: %v", err), http.StatusBadRequest)
|
http.Error(w, fmt.Sprintf("handler error: %v", err), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -166,9 +166,16 @@ func nethook(conf *simulations.NetworkConfig) (simulations.NetworkControl, *simu
|
||||||
&simulations.ResourceHandlers{
|
&simulations.ResourceHandlers{
|
||||||
Retrieve: &simulations.ResourceHandler{
|
Retrieve: &simulations.ResourceHandler{
|
||||||
Handle: func(msg interface{}, parent *simulations.ResourceController) (interface{}, error) {
|
Handle: func(msg interface{}, parent *simulations.ResourceController) (interface{}, error) {
|
||||||
id := msg.(string)
|
ids := msg.([]string)
|
||||||
pp := net.GetNode(adapters.NewNodeIdFromHex(id)).Adapter().(*SimNode).hive
|
var results []string
|
||||||
return pp.String(), nil
|
for _, id := range ids {
|
||||||
|
if len(id) != 128 {
|
||||||
|
return nil, fmt.Errorf("Nodes controller expects 128 bytes size hex id")
|
||||||
|
}
|
||||||
|
pp := net.GetNode(adapters.NewNodeIdFromHex(id)).Adapter().(*SimNode).hive
|
||||||
|
results = append(results, pp.String())
|
||||||
|
}
|
||||||
|
return results, nil
|
||||||
},
|
},
|
||||||
Type: reflect.TypeOf([]string{}), // this is input not output param structure
|
Type: reflect.TypeOf([]string{}), // this is input not output param structure
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue