From c78634df38059cec0e469bb1eb5a872ced0c44c0 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Tue, 29 Dec 2020 12:05:36 +0700 Subject: [PATCH] add a http3.RoundTripOpt to skip the request scheme check Otherwise, we'll only be able to issue https requests. This is what we usually want, but for MASQUE support, the URL will be of the form masque://example.org. --- http3/roundtrip.go | 11 ++++++----- http3/roundtrip_test.go | 9 +++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/http3/roundtrip.go b/http3/roundtrip.go index 264ed63f..b3462887 100644 --- a/http3/roundtrip.go +++ b/http3/roundtrip.go @@ -61,11 +61,12 @@ type RoundTripper struct { // RoundTripOpt are options for the Transport.RoundTripOpt method. type RoundTripOpt struct { - // OnlyCachedConn controls whether the RoundTripper may - // create a new QUIC connection. If set true and - // no cached connection is available, RoundTrip - // will return ErrNoCachedConn. + // OnlyCachedConn controls whether the RoundTripper may create a new QUIC connection. + // If set true and no cached connection is available, RoundTrip will return ErrNoCachedConn. OnlyCachedConn bool + // SkipSchemeCheck controls whether we check if the scheme is https. + // This allows the use of different schemes, e.g. masque://target.example.com:443/. + SkipSchemeCheck bool } var _ roundTripCloser = &RoundTripper{} @@ -99,7 +100,7 @@ func (r *RoundTripper) RoundTripOpt(req *http.Request, opt RoundTripOpt) (*http. } } } - } else { + } else if !opt.SkipSchemeCheck { closeRequestBody(req) return nil, fmt.Errorf("http3: unsupported protocol scheme: %s", req.URL.Scheme) } diff --git a/http3/roundtrip_test.go b/http3/roundtrip_test.go index b1b84758..cb07ab3e 100644 --- a/http3/roundtrip_test.go +++ b/http3/roundtrip_test.go @@ -179,6 +179,15 @@ var _ = Describe("RoundTripper", func() { Expect(req.Body.(*mockBody).closed).To(BeTrue()) }) + It("allow non-https schemes if SkipSchemeCheck is set", func() { + req, err := http.NewRequest("GET", "masque://www.example.org/", nil) + Expect(err).ToNot(HaveOccurred()) + _, err = rt.RoundTrip(req) + Expect(err).To(MatchError("http3: unsupported protocol scheme: masque")) + _, err = rt.RoundTripOpt(req, RoundTripOpt{SkipSchemeCheck: true, OnlyCachedConn: true}) + Expect(err).To(MatchError("http3: no cached connection was available")) + }) + It("rejects requests without a URL", func() { req1.URL = nil req1.Body = &mockBody{}