Skip to content

Commit

Permalink
Fix monzo#164 runtime panic on incomplete/invalid URL
Browse files Browse the repository at this point in the history
  • Loading branch information
Karel van IJperen authored and kvij committed May 28, 2023
1 parent ea17ae8 commit dcef1db
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func SendVia(req Request, svc Service) *ResponseFuture {
// Send round-trips the request via the default Client. It does not block, instead returning a ResponseFuture
// representing the asynchronous operation to produce the response. It is equivalent to:
//
// SendVia(req, Client)
// SendVia(req, Client)
func Send(req Request) *ResponseFuture {
return SendVia(req, Client)
}
Expand All @@ -123,10 +123,14 @@ func isH2C(ctx context.Context) bool {
return b
}

func isHTTP(r *http.Request) bool {
return r.URL != nil && r.URL.Scheme == "http"
}

type dynamicRoundTripper struct{}

func (d dynamicRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
if r.URL.Scheme == "http" && isH2C(r.Context()) {
if isHTTP(r) && isH2C(r.Context()) {
return H2cRoundTripper.RoundTrip(r)
}
return HTTPRoundTripper.RoundTrip(r)
Expand Down

0 comments on commit dcef1db

Please sign in to comment.