Skip to content

Commit

Permalink
fix http request instance null for websocket requests (0xPolygonHerme…
Browse files Browse the repository at this point in the history
  • Loading branch information
tclemos authored Aug 9, 2023
1 parent de58703 commit b18316e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions jsonrpc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,16 @@ func (h *Handler) Handle(req handleRequest) types.Response {
}

// HandleWs handle websocket requests
func (h *Handler) HandleWs(reqBody []byte, wsConn *websocket.Conn) ([]byte, error) {
func (h *Handler) HandleWs(reqBody []byte, wsConn *websocket.Conn, httpReq *http.Request) ([]byte, error) {
var req types.Request
if err := json.Unmarshal(reqBody, &req); err != nil {
return types.NewResponse(req, nil, types.NewRPCError(types.InvalidRequestErrorCode, "Invalid json request")).Bytes()
}

handleReq := handleRequest{
Request: req,
wsConn: wsConn,
Request: req,
wsConn: wsConn,
HttpRequest: httpReq,
}

return h.Handle(handleReq).Bytes()
Expand Down
2 changes: 1 addition & 1 deletion jsonrpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ func (s *Server) handleWs(w http.ResponseWriter, req *http.Request) {
go func() {
mu.Lock()
defer mu.Unlock()
resp, err := s.handler.HandleWs(message, wsConn)
resp, err := s.handler.HandleWs(message, wsConn, req)
if err != nil {
log.Error(fmt.Sprintf("Unable to handle WS request, %s", err.Error()))
_ = wsConn.WriteMessage(msgType, []byte(fmt.Sprintf("WS Handle error: %s", err.Error())))
Expand Down

0 comments on commit b18316e

Please sign in to comment.