diff --git a/contrib/codecs/http/codec.go b/contrib/codecs/http/codec.go index b3fb38d127b2973b61921853351aae8aaab8ea5a..ae14d5e9f1834412e0854b4e05ca05a107df6d38 100644 --- a/contrib/codecs/http/codec.go +++ b/contrib/codecs/http/codec.go @@ -65,7 +65,7 @@ func (c *Codec) Reset(w http.ResponseWriter, r *http.Request) { func (c *Codec) peerInfo() { c.i.Transport = "http" c.i.RemoteAddr = c.r.RemoteAddr - c.i.HTTP = &http.Request{} + c.i.HTTP = c.r.Clone(c.r.Context()) } // gets the peer info diff --git a/contrib/codecs/http/http_test.go b/contrib/codecs/http/http_test.go index c13b8acc59b0a02da773de810945c78d5557ac40..1e8c456f65367abcb4325a2285cdadf32cdee533 100644 --- a/contrib/codecs/http/http_test.go +++ b/contrib/codecs/http/http_test.go @@ -176,40 +176,6 @@ func TestHTTPErrorResponse(t *testing.T) { } } -func TestHTTPPeerInfo(t *testing.T) { - s := jrpctest.NewServer() - ts := httptest.NewServer(&Server{Server: s}) - defer ts.Close() - - c, err := DialHTTP(ts.URL) - if err != nil { - t.Fatal(err) - } - c.SetHeader("user-agent", "ua-testing") - c.SetHeader("x-forwarded-for", "origin.example.com") - - // Request peer information. - var info jsonrpc.PeerInfo - if err := c.Do(nil, &info, "test_peerInfo", nil); err != nil { - t.Fatal(err) - } - - if info.RemoteAddr == "" { - t.Error("RemoteAddr not set") - } - if info.Transport != "http" { - t.Errorf("wrong Transport %q", info.Transport) - } - if info.HTTP.Proto != "HTTP/1.1" { - t.Errorf("wrong HTTP.Version %q", info.HTTP.Proto) - } - if info.HTTP.UserAgent() != "ua-testing" { - t.Errorf("wrong HTTP.UserAgent %q", info.HTTP.UserAgent()) - } - if info.HTTP.Host != "origin.example.com" { - t.Errorf("wrong HTTP.Origin %q", info.HTTP.Host) - } -} func TestClientHTTP(t *testing.T) { s := jrpctest.NewServer() ts := httptest.NewServer(&Server{Server: s}) diff --git a/contrib/codecs/websocket/websocket_test.go b/contrib/codecs/websocket/websocket_test.go index b5e449795a72b1fc106de68ab58517556fee4fc0..04981d07bba2780539faaa64e52a127c886ea0e3 100644 --- a/contrib/codecs/websocket/websocket_test.go +++ b/contrib/codecs/websocket/websocket_test.go @@ -9,7 +9,6 @@ import ( "gfx.cafe/open/jrpc/contrib/codecs/websocket" "gfx.cafe/open/jrpc/contrib/jmux" "gfx.cafe/open/jrpc/pkg/jrpctest" - "gfx.cafe/open/jrpc/pkg/jsonrpc" "gfx.cafe/open/jrpc/pkg/server" ) @@ -95,40 +94,6 @@ func TestWebsocketLargeCall(t *testing.T) { } } -func TestWebsocketPeerInfo(t *testing.T) { - var ( - s = jrpctest.NewServer() - ts = httptest.NewServer(websocket.WebsocketHandler(s, []string{"origin.example.com"})) - tsurl = "ws:" + strings.TrimPrefix(ts.URL, "http:") - ) - defer ts.Close() - - ctx := context.Background() - c, err := websocket.DialWebsocket(ctx, tsurl, "http://origin.example.com") - if err != nil { - t.Fatal(err) - } - - // Request peer information. - var connInfo jsonrpc.PeerInfo - if err := c.Do(nil, &connInfo, "test_peerInfo", []any{}); err != nil { - t.Fatal(err) - } - - if connInfo.RemoteAddr == "" { - t.Error("RemoteAddr not set") - } - if connInfo.Transport != "ws" { - t.Errorf("wrong Transport %q", connInfo.Transport) - } - if connInfo.HTTP.UserAgent() != "Go-http-client/1.1" { - t.Errorf("wrong HTTP.UserAgent %q", connInfo.HTTP.UserAgent()) - } - if connInfo.HTTP.Host != "http://origin.example.com" { - t.Errorf("wrong HTTP.Origin %q", connInfo.HTTP.Host) - } -} - // This checks that the websocket transport can deal with large messages. func TestClientWebsocketLargeMessage(t *testing.T) { mux := jmux.NewMux() diff --git a/pkg/jsonrpc/peer.go b/pkg/jsonrpc/peer.go index 36bf95f66bb8fa93b856e5a380bbb0fdc40ded8b..b89d86084025adb0407ee5ba54c5aee120371b07 100644 --- a/pkg/jsonrpc/peer.go +++ b/pkg/jsonrpc/peer.go @@ -12,5 +12,5 @@ type PeerInfo struct { RemoteAddr string // Additional information for HTTP and WebSocket connections. - HTTP *http.Request + HTTP *http.Request `json:"-"` }