rpc: remove EnableCORSWorkaround from Request

This commit is contained in:
Evgenii Stratonikov 2019-12-30 13:42:33 +03:00
parent 289cb1c1d9
commit 45a4524054
2 changed files with 8 additions and 10 deletions

View file

@ -17,11 +17,10 @@ type (
// Request represents a standard JSON-RPC 2.0
// request: http://www.jsonrpc.org/specification#request_object.
Request struct {
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"`
RawParams json.RawMessage `json:"params,omitempty"`
RawID json.RawMessage `json:"id,omitempty"`
enableCORSWorkaround bool
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"`
RawParams json.RawMessage `json:"params,omitempty"`
RawID json.RawMessage `json:"id,omitempty"`
}
// Response represents a standard JSON-RPC 2.0
@ -35,10 +34,9 @@ type (
)
// NewRequest creates a new Request struct.
func NewRequest(corsWorkaround bool) *Request {
func NewRequest() *Request {
return &Request{
JSONRPC: jsonRPCVersion,
enableCORSWorkaround: corsWorkaround,
JSONRPC: jsonRPCVersion,
}
}
@ -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) {
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-Headers", "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With")
}

View file

@ -70,7 +70,7 @@ func (s *Server) Shutdown() error {
}
func (s *Server) requestHandler(w http.ResponseWriter, httpRequest *http.Request) {
req := NewRequest(s.config.EnableCORSWorkaround)
req := NewRequest()
if httpRequest.Method != "POST" {
s.WriteErrorResponse(