rpc: add PeerInfo (#24255)
This replaces the sketchy and undocumented string context keys for HTTP requests with a defined interface. Using string keys with context is discouraged because they may clash with keys created by other packages. We added these keys to make connection metadata available in the signer, so this change also updates signer/core to use the new PeerInfo API.
This commit is contained in:
@ -117,6 +117,41 @@ func TestWebsocketLargeCall(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWebsocketPeerInfo(t *testing.T) {
|
||||
var (
|
||||
s = newTestServer()
|
||||
ts = httptest.NewServer(s.WebsocketHandler([]string{"origin.example.com"}))
|
||||
tsurl = "ws:" + strings.TrimPrefix(ts.URL, "http:")
|
||||
)
|
||||
defer s.Stop()
|
||||
defer ts.Close()
|
||||
|
||||
ctx := context.Background()
|
||||
c, err := DialWebsocket(ctx, tsurl, "origin.example.com")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Request peer information.
|
||||
var connInfo PeerInfo
|
||||
if err := c.Call(&connInfo, "test_peerInfo"); 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.Origin != "origin.example.com" {
|
||||
t.Errorf("wrong HTTP.Origin %q", connInfo.HTTP.UserAgent)
|
||||
}
|
||||
}
|
||||
|
||||
// This test checks that client handles WebSocket ping frames correctly.
|
||||
func TestClientWebsocketPing(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
Reference in New Issue
Block a user