diff --git a/traffic/traffic.go b/traffic/traffic.go index e7c7f4fb..73a9cea6 100644 --- a/traffic/traffic.go +++ b/traffic/traffic.go @@ -2421,12 +2421,14 @@ func (t *Traffic) query(host, contains, bodyContains string, page, limit int) ([ authority := net.JoinHostPort(hostName, port) prefixes := []string{"%://" + authority} // Clients leave a default port out of the Host header, so a capture - // of https://host:443 is recorded as https://host. + // of https://host:443 is recorded as https://host, and a WebSocket + // over it as wss://host. + bare := strings.TrimSuffix(authority, ":"+port) switch port { case "80": - prefixes = append(prefixes, "http://"+strings.TrimSuffix(authority, ":80")) + prefixes = append(prefixes, "http://"+bare, "ws://"+bare) case "443": - prefixes = append(prefixes, "https://"+strings.TrimSuffix(authority, ":443")) + prefixes = append(prefixes, "https://"+bare, "wss://"+bare) } var conds []string for _, p := range prefixes { diff --git a/traffic/traffic_store_test.go b/traffic/traffic_store_test.go index a1034703..81dad35e 100644 --- a/traffic/traffic_store_test.go +++ b/traffic/traffic_store_test.go @@ -455,6 +455,11 @@ func TestQueryHostDefaultPort(t *testing.T) { v6 := newFlow("x", "GET", "/", nil, []byte("v6")) v6.Request.URL, _ = url.Parse("https://[2001:db8::1]/admin") tr.record(v6) + ws := newFlow("x", "GET", "/", nil, nil) + ws.Request.URL, _ = url.Parse("https://chat.example.com/socket") + if _, err := tr.recordStreamStart(flowRequestView(ws.Request), responseView{}, "websocket", nil); err != nil { + t.Fatal(err) + } for _, tc := range []struct { host string @@ -466,6 +471,7 @@ func TestQueryHostDefaultPort(t *testing.T) { {host: "http://shop.example.com:80/", want: "http://shop.example.com/plain"}, {host: "shop.example.com:8443", want: "http://shop.example.com:8443/alt"}, {host: "[2001:db8::1]:443", want: "https://[2001:db8::1]/admin"}, + {host: "chat.example.com:443", want: "wss://chat.example.com/socket"}, } { rows, err := tr.query(tc.host, "", "", 0, 10) if err != nil {