@@ -2169,32 +2169,72 @@ func TestWebXUserAgent(t *testing.T) {
21692169
21702170func TestBidiOverHTTP1 (t * testing.T ) {
21712171 t .Parallel ()
2172- mux := http .NewServeMux ()
2173- mux .Handle (pingv1connect .NewPingServiceHandler (pingServer {}))
2174- server := memhttptest .NewServer (t , mux )
21752172
2176- // Clients expecting a full-duplex connection that end up with a simplex
2177- // HTTP/1.1 connection shouldn't hang. Instead, the server should close the
2178- // TCP connection.
2179- client := pingv1connect .NewPingServiceClient (
2180- & http.Client {Transport : server .TransportHTTP1 ()},
2181- server .URL (),
2182- // connect.WithExperimental(connect.ExperimentalFeatures{
2183- // AllowBidiStreamOverHTTP11: true,
2184- // }),
2185- )
2186- stream := client .CumSum (context .Background ())
2187- // Stream creates an async request, can error on Send or Receive.
2188- if err := stream .Send (& pingv1.CumSumRequest {Number : 2 }); err != nil {
2189- assert .ErrorIs (t , err , io .EOF )
2173+ type testCase struct {
2174+ name string
2175+ handlerOptions []connect.HandlerOption
2176+ clientOptions []connect.ClientOption
2177+ validate func (* testing.T , * pingv1.CumSumResponse , error )
21902178 }
2191- _ , err := stream .Receive ()
2192- assert .Equal (t , connect .CodeOf (err ), connect .CodeUnknown )
2193- assert .NotNil (t , err )
2194- assert .Equal (t , err .Error (), "unknown: HTTP status 505 HTTP Version Not Supported" )
21952179
2196- assert .Nil (t , stream .CloseRequest ())
2197- assert .Nil (t , stream .CloseResponse ())
2180+ for _ , tc := range []testCase {
2181+ {
2182+ name : "disallow bidi stream over http1" ,
2183+ handlerOptions : []connect.HandlerOption {},
2184+ clientOptions : []connect.ClientOption {},
2185+ validate : func (t * testing.T , csr * pingv1.CumSumResponse , err error ) {
2186+ assert .Equal (t , connect .CodeOf (err ), connect .CodeUnknown )
2187+ assert .NotNil (t , err )
2188+ assert .Equal (t , err .Error (), "unknown: HTTP status 505 HTTP Version Not Supported" )
2189+ },
2190+ },
2191+ {
2192+ name : "allow bidi stream over http1" ,
2193+ handlerOptions : []connect.HandlerOption {
2194+ connect .WithExperimental (connect.ExperimentalFeatures {
2195+ AllowBidiStreamOverHTTP11 : true ,
2196+ }),
2197+ },
2198+ clientOptions : []connect.ClientOption {
2199+ connect .WithExperimental (connect.ExperimentalFeatures {
2200+ AllowBidiStreamOverHTTP11 : true ,
2201+ }),
2202+ },
2203+ validate : func (t * testing.T , csr * pingv1.CumSumResponse , err error ) {
2204+ assert .NotNil (t , csr )
2205+ assert .Equal (t , 2 , csr .Sum )
2206+ assert .Nil (t , err )
2207+ },
2208+ },
2209+ } {
2210+ t .Run (tc .name , func (t * testing.T ) {
2211+ mux := http .NewServeMux ()
2212+ mux .Handle (pingv1connect .NewPingServiceHandler (
2213+ pingServer {},
2214+ tc .handlerOptions ... ,
2215+ ))
2216+ server := memhttptest .NewServer (t , mux )
2217+
2218+ // Clients expecting a full-duplex connection that end up with a simplex
2219+ // HTTP/1.1 connection shouldn't hang. Instead, the server should close the
2220+ // TCP connection.
2221+ client := pingv1connect .NewPingServiceClient (
2222+ & http.Client {Transport : server .TransportHTTP1 ()},
2223+ server .URL (),
2224+ tc .clientOptions ... ,
2225+ )
2226+ stream := client .CumSum (context .Background ())
2227+ // Stream creates an async request, can error on Send or Receive.
2228+ if err := stream .Send (& pingv1.CumSumRequest {Number : 2 }); err != nil {
2229+ assert .ErrorIs (t , err , io .EOF )
2230+ }
2231+ recvMsg , err := stream .Receive ()
2232+ tc .validate (t , recvMsg , err )
2233+
2234+ assert .Nil (t , stream .CloseRequest ())
2235+ assert .Nil (t , stream .CloseResponse ())
2236+ })
2237+ }
21982238}
21992239
22002240func TestHandlerReturnsNilResponse (t * testing.T ) {
0 commit comments