ipn/ipnlocal: proxy gRPC requests over h2c if needed. (#9847)

Updates userspace proxy to detect plaintext grpc requests
using the preconfigured host prefix and request's content
type header and ensure that these will be proxied over h2c.

Updates tailscale/tailscale#9725

Signed-off-by: Irbe Krumina <irbe@tailscale.com>
This commit is contained in:
Irbe Krumina
2023-10-19 07:12:31 +01:00
committed by GitHub
parent 891d964bd4
commit 09b5bb3e55
2 changed files with 114 additions and 13 deletions

View File

@@ -587,3 +587,39 @@ func TestServeFileOrDirectory(t *testing.T) {
}
}
}
func Test_isGRPCContentType(t *testing.T) {
tests := map[string]struct {
contentType string
want bool
}{
"application/grpc": {
contentType: "application/grpc",
want: true,
},
"application/grpc;": {
contentType: "application/grpc;",
want: true,
},
"application/grpc+": {
contentType: "application/grpc+",
want: true,
},
"application/grpcfoobar": {
contentType: "application/grpcfoobar",
},
"application/text": {
contentType: "application/text",
},
"foobar": {
contentType: "foobar",
},
}
for name, scenario := range tests {
t.Run(name, func(t *testing.T) {
if got := isGRPCContentType(scenario.contentType); got != scenario.want {
t.Errorf("test case %s failed, isGRPCContentType() = %v, want %v", name, got, scenario.want)
}
})
}
}