rpc: allow RPC requests on GET too
This commit is contained in:
parent
db056eeafe
commit
72c255caef
28
rpc/http.go
28
rpc/http.go
@ -18,21 +18,19 @@ package rpc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"errors"
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"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"
|
||||||
@ -57,8 +55,7 @@ var (
|
|||||||
type httpMessageStream struct {
|
type httpMessageStream struct {
|
||||||
conn net.Conn // TCP connection
|
conn net.Conn // TCP connection
|
||||||
rw *bufio.ReadWriter // buffered where HTTP requests/responses are read/written from/to
|
rw *bufio.ReadWriter // buffered where HTTP requests/responses are read/written from/to
|
||||||
currentReq *http.Request // pending request, codec can pass in a too small buffer for a single read
|
currentReq *http.Request // pending request, codec can pass in a too small buffer for a single read we need to keep track of the current requests if it was not read at once
|
||||||
// we need to keep track of the current requests if it was not read at once
|
|
||||||
payloadBytesRead int64 // number of bytes which are read from the current request
|
payloadBytesRead int64 // number of bytes which are read from the current request
|
||||||
allowedOrigins *set.Set // allowed CORS domains
|
allowedOrigins *set.Set // allowed CORS domains
|
||||||
origin string // origin of this connection/request
|
origin string // origin of this connection/request
|
||||||
@ -147,7 +144,7 @@ func (h *httpMessageStream) Read(buf []byte) (n int, err error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.EqualFold(h.currentReq.Method, "POST") {
|
if strings.EqualFold(h.currentReq.Method, "GET") || strings.EqualFold(h.currentReq.Method, "POST") {
|
||||||
n, err := h.currentReq.Body.Read(buf)
|
n, err := h.currentReq.Body.Read(buf)
|
||||||
h.payloadBytesRead += int64(n)
|
h.payloadBytesRead += int64(n)
|
||||||
|
|
||||||
@ -164,12 +161,9 @@ func (h *httpMessageStream) Read(buf []byte) (n int, err error) {
|
|||||||
h.currentReq = nil
|
h.currentReq = nil
|
||||||
h.payloadBytesRead = 0
|
h.payloadBytesRead = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// partial read of body
|
// partial read of body
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
h.currentReq = nil
|
|
||||||
return 0, fmt.Errorf("unsupported HTTP method '%s'", h.currentReq.Method)
|
return 0, fmt.Errorf("unsupported HTTP method '%s'", h.currentReq.Method)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user