Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove connect-go reference implementation workaround for HTTP/1.x streams #942

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions internal/app/referenceclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -188,21 +187,10 @@ func invoke(ctx context.Context, req *conformancev1.ClientCompatRequest, referen
if tlsConf != nil {
tlsConf.NextProtos = []string{"http/1.1"}
}
tx := &http.Transport{
transport = &http.Transport{
DisableCompression: true,
TLSClientConfig: tlsConf,
}
transport = roundTripperFunc(func(req *http.Request) (*http.Response, error) {
resp, err := tx.RoundTrip(req)
if resp != nil &&
strings.HasSuffix(req.URL.Path, conformancev1connect.ConformanceServiceBidiStreamProcedure) {
// To force support for bidirectional RPC over HTTP 1.1 (for half-duplex testing),
// we "trick" the client into thinking this is HTTP/2. We have to do this because
// otherwise, connect-go refuses to support bidi streams over HTTP 1.1.
resp.ProtoMajor, resp.ProtoMinor = 2, 0
}
return resp, err
})
case conformancev1.HTTPVersion_HTTP_VERSION_2:
if tlsConf != nil {
tlsConf.NextProtos = []string{"h2"}
Expand Down Expand Up @@ -408,9 +396,3 @@ func (e *contextFixError) Is(err error) bool {
return (e.timeout && err == context.DeadlineExceeded) ||
(!e.timeout && err == context.Canceled)
}

type roundTripperFunc func(*http.Request) (*http.Response, error)

func (f roundTripperFunc) RoundTrip(req *http.Request) (*http.Response, error) {
return f(req)
}
6 changes: 6 additions & 0 deletions internal/app/referenceclient/raw_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,3 +433,9 @@ func TestRawRequestSender(t *testing.T) {
})
}
}

type roundTripperFunc func(*http.Request) (*http.Response, error)

func (f roundTripperFunc) RoundTrip(req *http.Request) (*http.Response, error) {
return f(req)
}
11 changes: 1 addition & 10 deletions internal/app/referenceserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,7 @@ func createServer(req *conformancev1.ServerCompatRequest, listenAddr, tlsCertFil
&conformanceServer{referenceMode: referenceMode},
opts...,
))
handler := http.Handler(http.HandlerFunc(func(respWriter http.ResponseWriter, req *http.Request) {
if strings.HasSuffix(req.URL.Path, conformancev1connect.ConformanceServiceBidiStreamProcedure) &&
req.ProtoMajor == 1 {
// To force support for bidirectional RPC over HTTP 1.1 (for half-duplex testing),
// we "trick" the handler into thinking this is HTTP/2. We have to do this because
// otherwise, connect-go refuses to handle bidi streams over HTTP 1.1.
req.ProtoMajor, req.ProtoMinor = 2, 0
}
mux.ServeHTTP(respWriter, req)
}))
handler := (http.Handler)(mux)
if referenceMode {
handler = referenceServerChecks(handler, errPrinter)
handler = rawResponder(handler)
Expand Down
Loading