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

Fix #164 runtime panic on incomplete/invalid URL #165

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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