forked from TrueCloudLab/neoneo-go
rpc: remove EnableCORSWorkaround from Request
This commit is contained in:
parent
289cb1c1d9
commit
45a4524054
2 changed files with 8 additions and 10 deletions
|
@ -17,11 +17,10 @@ type (
|
||||||
// Request represents a standard JSON-RPC 2.0
|
// Request represents a standard JSON-RPC 2.0
|
||||||
// request: http://www.jsonrpc.org/specification#request_object.
|
// request: http://www.jsonrpc.org/specification#request_object.
|
||||||
Request struct {
|
Request struct {
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
Method string `json:"method"`
|
Method string `json:"method"`
|
||||||
RawParams json.RawMessage `json:"params,omitempty"`
|
RawParams json.RawMessage `json:"params,omitempty"`
|
||||||
RawID json.RawMessage `json:"id,omitempty"`
|
RawID json.RawMessage `json:"id,omitempty"`
|
||||||
enableCORSWorkaround bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Response represents a standard JSON-RPC 2.0
|
// Response represents a standard JSON-RPC 2.0
|
||||||
|
@ -35,10 +34,9 @@ type (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewRequest creates a new Request struct.
|
// NewRequest creates a new Request struct.
|
||||||
func NewRequest(corsWorkaround bool) *Request {
|
func NewRequest() *Request {
|
||||||
return &Request{
|
return &Request{
|
||||||
JSONRPC: jsonRPCVersion,
|
JSONRPC: jsonRPCVersion,
|
||||||
enableCORSWorkaround: corsWorkaround,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +112,7 @@ func (s *Server) WriteResponse(r *Request, w http.ResponseWriter, result interfa
|
||||||
|
|
||||||
func (s *Server) writeServerResponse(r *Request, w http.ResponseWriter, response Response) {
|
func (s *Server) writeServerResponse(r *Request, w http.ResponseWriter, response Response) {
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
if r.enableCORSWorkaround {
|
if s.config.EnableCORSWorkaround {
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With")
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With")
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ func (s *Server) Shutdown() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) requestHandler(w http.ResponseWriter, httpRequest *http.Request) {
|
func (s *Server) requestHandler(w http.ResponseWriter, httpRequest *http.Request) {
|
||||||
req := NewRequest(s.config.EnableCORSWorkaround)
|
req := NewRequest()
|
||||||
|
|
||||||
if httpRequest.Method != "POST" {
|
if httpRequest.Method != "POST" {
|
||||||
s.WriteErrorResponse(
|
s.WriteErrorResponse(
|
||||||
|
|
Loading…
Reference in a new issue