Simplify go17 and go18 differences to support http2 WrapWriter
This commit is contained in:
parent
be7a9b90e7
commit
55c93631d1
13 changed files with 209 additions and 360 deletions
|
|
@ -1,11 +1,9 @@
|
|||
package middleware
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"compress/flate"
|
||||
"compress/gzip"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
|
@ -62,7 +60,7 @@ func Compress(level int, types ...string) func(next http.Handler) http.Handler {
|
|||
}
|
||||
defer mcw.Close()
|
||||
|
||||
next.ServeHTTP(mkGenericWrapper(mcw), r)
|
||||
next.ServeHTTP(mcw, r)
|
||||
}
|
||||
|
||||
return http.HandlerFunc(fn)
|
||||
|
|
@ -175,82 +173,15 @@ func (w *maybeCompressResponseWriter) Write(p []byte) (int, error) {
|
|||
return w.w.Write(p)
|
||||
}
|
||||
|
||||
func (w *maybeCompressResponseWriter) Unwrap() http.ResponseWriter {
|
||||
return w.ResponseWriter
|
||||
func (w *maybeCompressResponseWriter) Flush() {
|
||||
if f, ok := w.w.(http.Flusher); ok {
|
||||
f.Flush()
|
||||
}
|
||||
}
|
||||
|
||||
func (w *maybeCompressResponseWriter) Close() error {
|
||||
if c, ok := w.w.(io.Closer); ok {
|
||||
if c, ok := w.w.(io.WriteCloser); ok {
|
||||
return c.Close()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type responseWriterWrapper interface {
|
||||
http.ResponseWriter
|
||||
Unwrap() http.ResponseWriter
|
||||
}
|
||||
|
||||
type genericWrapper struct {
|
||||
inner responseWriterWrapper
|
||||
}
|
||||
|
||||
func (g *genericWrapper) Unwrap() http.ResponseWriter {
|
||||
return g.inner
|
||||
}
|
||||
|
||||
func (g *genericWrapper) Header() http.Header {
|
||||
return g.inner.Header()
|
||||
}
|
||||
|
||||
func (g *genericWrapper) Write(data []byte) (int, error) {
|
||||
return g.inner.Write(data)
|
||||
}
|
||||
|
||||
func (g *genericWrapper) WriteHeader(status int) {
|
||||
g.inner.WriteHeader(status)
|
||||
}
|
||||
|
||||
var _ http.ResponseWriter = &genericWrapper{}
|
||||
|
||||
type httpGenericWrapper struct {
|
||||
genericWrapper
|
||||
}
|
||||
|
||||
func (h *httpGenericWrapper) CloseNotify() <-chan bool {
|
||||
if cn, ok := h.genericWrapper.inner.(http.CloseNotifier); ok {
|
||||
return cn.CloseNotify()
|
||||
}
|
||||
|
||||
return h.genericWrapper.inner.Unwrap().(http.CloseNotifier).CloseNotify()
|
||||
}
|
||||
func (h *httpGenericWrapper) Flush() {
|
||||
if f, ok := h.genericWrapper.inner.(http.Flusher); ok {
|
||||
f.Flush()
|
||||
return
|
||||
}
|
||||
|
||||
h.genericWrapper.inner.Unwrap().(http.Flusher).Flush()
|
||||
}
|
||||
|
||||
func (h *httpGenericWrapper) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||
if hj, ok := h.genericWrapper.inner.(http.Hijacker); ok {
|
||||
return hj.Hijack()
|
||||
}
|
||||
|
||||
return h.genericWrapper.inner.Unwrap().(http.Hijacker).Hijack()
|
||||
}
|
||||
|
||||
func (h *httpGenericWrapper) ReadFrom(r io.Reader) (n int64, err error) {
|
||||
if rf, ok := h.genericWrapper.inner.(io.ReaderFrom); ok {
|
||||
return rf.ReadFrom(r)
|
||||
}
|
||||
|
||||
return h.genericWrapper.inner.Unwrap().(io.ReaderFrom).ReadFrom(r)
|
||||
}
|
||||
|
||||
var _ http.ResponseWriter = &httpGenericWrapper{}
|
||||
var _ http.CloseNotifier = &httpGenericWrapper{}
|
||||
var _ http.Flusher = &httpGenericWrapper{}
|
||||
var _ http.Hijacker = &httpGenericWrapper{}
|
||||
var _ io.ReaderFrom = &httpGenericWrapper{}
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
// +build !go1.8
|
||||
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func mkGenericWrapper(wrapper responseWriterWrapper) http.ResponseWriter {
|
||||
orig := wrapper.Unwrap()
|
||||
_, cn := orig.(http.CloseNotifier)
|
||||
_, fl := orig.(http.Flusher)
|
||||
_, hj := orig.(http.Hijacker)
|
||||
_, rf := orig.(io.ReaderFrom)
|
||||
|
||||
gw := genericWrapper{wrapper}
|
||||
if cn && fl && hj && rf && !ps {
|
||||
return &httpGenericWrapper{gw}
|
||||
}
|
||||
return &gw
|
||||
}
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
// +build go1.8
|
||||
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func mkGenericWrapper(wrapper responseWriterWrapper) http.ResponseWriter {
|
||||
orig := wrapper.Unwrap()
|
||||
_, cn := orig.(http.CloseNotifier)
|
||||
_, fl := orig.(http.Flusher)
|
||||
_, hj := orig.(http.Hijacker)
|
||||
_, rf := orig.(io.ReaderFrom)
|
||||
_, ps := orig.(http.Pusher)
|
||||
|
||||
gw := genericWrapper{wrapper}
|
||||
if cn && fl && !hj && !rf && ps {
|
||||
return &http2GenericWrapper{gw}
|
||||
}
|
||||
if cn && fl && hj && rf && !ps {
|
||||
return &httpGenericWrapper{gw}
|
||||
}
|
||||
return &gw
|
||||
}
|
||||
|
||||
type http2GenericWrapper struct {
|
||||
genericWrapper
|
||||
}
|
||||
|
||||
func (h *http2GenericWrapper) CloseNotify() <-chan bool {
|
||||
if cn, ok := h.genericWrapper.inner.(http.CloseNotifier); ok {
|
||||
return cn.CloseNotify()
|
||||
}
|
||||
|
||||
return h.genericWrapper.inner.Unwrap().(http.CloseNotifier).CloseNotify()
|
||||
}
|
||||
func (h *http2GenericWrapper) Flush() {
|
||||
if f, ok := h.genericWrapper.inner.(http.Flusher); ok {
|
||||
f.Flush()
|
||||
return
|
||||
}
|
||||
|
||||
h.genericWrapper.inner.Unwrap().(http.Flusher).Flush()
|
||||
}
|
||||
func (h *http2GenericWrapper) Push(path string, opts *http.PushOptions) error {
|
||||
if p, ok := h.genericWrapper.inner.(http.Pusher); ok {
|
||||
return p.Push(path, opts)
|
||||
}
|
||||
|
||||
return h.genericWrapper.inner.Unwrap().(http.Pusher).Push(path, opts)
|
||||
}
|
||||
|
||||
var _ http.ResponseWriter = &http2GenericWrapper{}
|
||||
var _ http.CloseNotifier = &http2GenericWrapper{}
|
||||
var _ http.Flusher = &http2GenericWrapper{}
|
||||
var _ http.Pusher = &http2GenericWrapper{}
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
// +build go1.8
|
||||
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"io"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/http2"
|
||||
)
|
||||
|
||||
// TestGenericWrapperHTTP2 tests that when an http2 request is wrapped using mkGenericWrapper, it still supports the
|
||||
// various interfaces that a http.http2responseWriter implements.
|
||||
func TestGenericWrapperHTTP2(t *testing.T) {
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
_, cn := w.(http.CloseNotifier)
|
||||
if !cn {
|
||||
t.Fatal("request should have been a http.CloseNotifier")
|
||||
}
|
||||
_, fl := w.(http.Flusher)
|
||||
if !fl {
|
||||
t.Fatal("request should have been a http.Flusher")
|
||||
}
|
||||
_, hj := w.(http.Hijacker)
|
||||
if hj {
|
||||
t.Fatal("request should not have been a http.Hijacker")
|
||||
}
|
||||
_, rf := w.(io.ReaderFrom)
|
||||
if rf {
|
||||
t.Fatal("request should not have been a io.ReaderFrom")
|
||||
}
|
||||
_, ps := w.(http.Pusher)
|
||||
if !ps {
|
||||
t.Fatal("request should have been a http.Pusher")
|
||||
}
|
||||
|
||||
w.Write([]byte("OK"))
|
||||
})
|
||||
|
||||
server := http.Server{
|
||||
Addr: ":7072",
|
||||
Handler: identityMiddleware(handler),
|
||||
}
|
||||
// By serving over TLS, we get HTTP2 requests
|
||||
go server.ListenAndServeTLS("./testing/cert.pem", "./testing/key.pem")
|
||||
defer server.Close()
|
||||
// We need the server to start before making the request
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
client := &http.Client{
|
||||
Transport: &http2.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
// The certificates we are using are self signed
|
||||
InsecureSkipVerify: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
resp, err := client.Get("https://localhost:7072")
|
||||
if err != nil {
|
||||
t.Fatalf("could not get server: %v", err)
|
||||
}
|
||||
if resp.StatusCode != 200 {
|
||||
t.Fatalf("non 200 response: %v", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
package middleware
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type emptyResponseWriterWrapper struct {
|
||||
inner http.ResponseWriter
|
||||
}
|
||||
|
||||
func (e *emptyResponseWriterWrapper) Header() http.Header {
|
||||
return e.inner.Header()
|
||||
}
|
||||
func (e *emptyResponseWriterWrapper) Write(data []byte) (int, error) {
|
||||
return e.inner.Write(data)
|
||||
}
|
||||
func (e *emptyResponseWriterWrapper) WriteHeader(status int) {
|
||||
e.inner.WriteHeader(status)
|
||||
}
|
||||
func (e *emptyResponseWriterWrapper) Unwrap() http.ResponseWriter {
|
||||
return e.inner
|
||||
}
|
||||
|
||||
func identityMiddleware(inner http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w = mkGenericWrapper(&emptyResponseWriterWrapper{w})
|
||||
inner.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
// TestGenericWrapperHTTP tests that when an http request is wrapped using mkGenericWrapper, it still supports the
|
||||
// various interfaces that a http.response implements.
|
||||
func TestGenericWrapperHTTP(t *testing.T) {
|
||||
t.Parallel()
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
_, cn := w.(http.CloseNotifier)
|
||||
if !cn {
|
||||
t.Fatal("request should have been a http.CloseNotifier")
|
||||
}
|
||||
_, fl := w.(http.Flusher)
|
||||
if !fl {
|
||||
t.Fatal("request should have been a http.Flusher")
|
||||
}
|
||||
_, hj := w.(http.Hijacker)
|
||||
if !hj {
|
||||
t.Fatal("request should have been a http.Hijacker")
|
||||
}
|
||||
_, rf := w.(io.ReaderFrom)
|
||||
if !rf {
|
||||
t.Fatal("request should have been a io.ReaderFrom")
|
||||
}
|
||||
|
||||
w.Write([]byte("OK"))
|
||||
})
|
||||
|
||||
server := httptest.NewServer(identityMiddleware(handler))
|
||||
defer server.Close()
|
||||
|
||||
resp, err := http.Get(server.URL)
|
||||
if err != nil {
|
||||
t.Fatalf("could not get server: %v", err)
|
||||
}
|
||||
if resp.StatusCode != 200 {
|
||||
t.Fatalf("non 200 response: %v", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
|
@ -29,7 +29,7 @@ func RequestLogger(f LogFormatter) func(next http.Handler) http.Handler {
|
|||
return func(next http.Handler) http.Handler {
|
||||
fn := func(w http.ResponseWriter, r *http.Request) {
|
||||
entry := f.NewLogEntry(r)
|
||||
ww := NewWrapResponseWriter(w)
|
||||
ww := NewWrapResponseWriter(w, r.ProtoMajor)
|
||||
|
||||
t1 := time.Now()
|
||||
defer func() {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,87 @@
|
|||
// +build go1.8
|
||||
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"path"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/http2"
|
||||
)
|
||||
|
||||
// NOTE: we must import `golang.org/x/net/http2` in order to explicitly enable
|
||||
// http2 transports for certain tests. The runtime pkg does not have this dependency
|
||||
// though as the transport configuration happens under the hood on go 1.7+.
|
||||
|
||||
var testdataDir string
|
||||
|
||||
func init() {
|
||||
_, filename, _, _ := runtime.Caller(0)
|
||||
testdataDir = path.Join(path.Dir(filename), "/../testdata")
|
||||
}
|
||||
|
||||
func TestWrapWriterHTTP2(t *testing.T) {
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
_, cn := w.(http.CloseNotifier)
|
||||
if !cn {
|
||||
t.Fatal("request should have been a http.CloseNotifier")
|
||||
}
|
||||
_, fl := w.(http.Flusher)
|
||||
if !fl {
|
||||
t.Fatal("request should have been a http.Flusher")
|
||||
}
|
||||
_, hj := w.(http.Hijacker)
|
||||
if hj {
|
||||
t.Fatal("request should not have been a http.Hijacker")
|
||||
}
|
||||
_, rf := w.(io.ReaderFrom)
|
||||
if rf {
|
||||
t.Fatal("request should not have been a io.ReaderFrom")
|
||||
}
|
||||
_, ps := w.(http.Pusher)
|
||||
if !ps {
|
||||
t.Fatal("request should have been a http.Pusher")
|
||||
}
|
||||
|
||||
w.Write([]byte("OK"))
|
||||
})
|
||||
|
||||
server := http.Server{
|
||||
Addr: ":7072",
|
||||
Handler: handler,
|
||||
}
|
||||
// By serving over TLS, we get HTTP2 requests
|
||||
go server.ListenAndServeTLS(testdataDir+"/cert.pem", testdataDir+"/key.pem")
|
||||
defer server.Close()
|
||||
// We need the server to start before making the request
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
client := &http.Client{
|
||||
Transport: &http2.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
// The certificates we are using are self signed
|
||||
InsecureSkipVerify: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
resp, err := client.Get("https://localhost:7072")
|
||||
if err != nil {
|
||||
t.Fatalf("could not get server: %v", err)
|
||||
}
|
||||
if resp.StatusCode != 200 {
|
||||
t.Fatalf("non 200 response: %v", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
func testRequest(t *testing.T, ts *httptest.Server, method, path string, body io.Reader) (int, string) {
|
||||
req, err := http.NewRequest(method, ts.URL+path, body)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@ import (
|
|||
"net/http"
|
||||
)
|
||||
|
||||
var WrapResponseWriterCtxKey = &contextKey{"WrapResponseWriter"}
|
||||
|
||||
// WrapResponseWriter is a proxy around an http.ResponseWriter that allows you to hook
|
||||
// into various parts of the response process.
|
||||
type WrapResponseWriter interface {
|
||||
|
|
@ -80,7 +78,18 @@ func (b *basicWriter) Unwrap() http.ResponseWriter {
|
|||
return b.ResponseWriter
|
||||
}
|
||||
|
||||
// httpFancyWriter is a writer that additionally satisfies http.CloseNotifier,
|
||||
type flushWriter struct {
|
||||
basicWriter
|
||||
}
|
||||
|
||||
func (f *flushWriter) Flush() {
|
||||
fl := f.basicWriter.ResponseWriter.(http.Flusher)
|
||||
fl.Flush()
|
||||
}
|
||||
|
||||
var _ http.Flusher = &flushWriter{}
|
||||
|
||||
// httpFancyWriter is a HTTP writer that additionally satisfies http.CloseNotifier,
|
||||
// http.Flusher, http.Hijacker, and io.ReaderFrom. It exists for the common case
|
||||
// of wrapping the http.ResponseWriter that package http gives you, in order to
|
||||
// make the proxied object support the full method set of the proxied object.
|
||||
|
|
@ -114,13 +123,31 @@ var _ http.Flusher = &httpFancyWriter{}
|
|||
var _ http.Hijacker = &httpFancyWriter{}
|
||||
var _ io.ReaderFrom = &httpFancyWriter{}
|
||||
|
||||
type flushWriter struct {
|
||||
// http2FancyWriter is a HTTP2 writer that additionally satisfies http.CloseNotifier,
|
||||
// http.Flusher, and io.ReaderFrom. It exists for the common case
|
||||
// of wrapping the http.ResponseWriter that package http gives you, in order to
|
||||
// make the proxied object support the full method set of the proxied object.
|
||||
type http2FancyWriter struct {
|
||||
basicWriter
|
||||
}
|
||||
|
||||
func (f *flushWriter) Flush() {
|
||||
func (f *http2FancyWriter) CloseNotify() <-chan bool {
|
||||
cn := f.basicWriter.ResponseWriter.(http.CloseNotifier)
|
||||
return cn.CloseNotify()
|
||||
}
|
||||
func (f *http2FancyWriter) Flush() {
|
||||
fl := f.basicWriter.ResponseWriter.(http.Flusher)
|
||||
fl.Flush()
|
||||
}
|
||||
func (f *http2FancyWriter) ReadFrom(r io.Reader) (int64, error) {
|
||||
if f.basicWriter.tee != nil {
|
||||
return io.Copy(&f.basicWriter, r)
|
||||
}
|
||||
rf := f.basicWriter.ResponseWriter.(io.ReaderFrom)
|
||||
f.basicWriter.maybeWriteHeader()
|
||||
return rf.ReadFrom(r)
|
||||
}
|
||||
|
||||
var _ http.Flusher = &flushWriter{}
|
||||
var _ http.CloseNotifier = &http2FancyWriter{}
|
||||
var _ http.Flusher = &http2FancyWriter{}
|
||||
var _ io.ReaderFrom = &http2FancyWriter{}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// +build !go1.8
|
||||
// +build go1.7,!go1.8
|
||||
|
||||
package middleware
|
||||
|
||||
|
|
@ -9,15 +9,21 @@ import (
|
|||
|
||||
// NewWrapResponseWriter wraps an http.ResponseWriter, returning a proxy that allows you to
|
||||
// hook into various parts of the response process.
|
||||
func NewWrapResponseWriter(w http.ResponseWriter) WrapResponseWriter {
|
||||
func NewWrapResponseWriter(w http.ResponseWriter, protoMajor int) WrapResponseWriter {
|
||||
_, cn := w.(http.CloseNotifier)
|
||||
_, fl := w.(http.Flusher)
|
||||
_, hj := w.(http.Hijacker)
|
||||
_, rf := w.(io.ReaderFrom)
|
||||
|
||||
bw := basicWriter{ResponseWriter: w}
|
||||
if cn && fl && hj && rf {
|
||||
return &httpFancyWriter{bw}
|
||||
if protoMajor == 2 {
|
||||
if cn && fl && rf {
|
||||
return &http2FancyWriter{bw}
|
||||
}
|
||||
} else {
|
||||
_, hj := w.(http.Hijacker)
|
||||
if cn && fl && hj && rf {
|
||||
return &httpFancyWriter{bw}
|
||||
}
|
||||
}
|
||||
if fl {
|
||||
return &flushWriter{bw}
|
||||
39
middleware/wrap_writer_18.go
Normal file
39
middleware/wrap_writer_18.go
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
// +build go1.8
|
||||
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// NewWrapResponseWriter wraps an http.ResponseWriter, returning a proxy that allows you to
|
||||
// hook into various parts of the response process.
|
||||
func NewWrapResponseWriter(w http.ResponseWriter, protoMajor int) WrapResponseWriter {
|
||||
_, cn := w.(http.CloseNotifier)
|
||||
_, fl := w.(http.Flusher)
|
||||
_, rf := w.(io.ReaderFrom)
|
||||
|
||||
bw := basicWriter{ResponseWriter: w}
|
||||
if protoMajor == 2 {
|
||||
_, ps := w.(http.Pusher)
|
||||
if cn && fl && ps && rf {
|
||||
return &http2FancyWriter{bw}
|
||||
}
|
||||
} else {
|
||||
_, hj := w.(http.Hijacker)
|
||||
if cn && fl && hj && rf {
|
||||
return &httpFancyWriter{bw}
|
||||
}
|
||||
}
|
||||
if fl {
|
||||
return &flushWriter{bw}
|
||||
}
|
||||
return &bw
|
||||
}
|
||||
|
||||
func (f *http2FancyWriter) Push(target string, opts *http.PushOptions) error {
|
||||
return f.basicWriter.ResponseWriter.(http.Pusher).Push(target, opts)
|
||||
}
|
||||
|
||||
var _ http.Pusher = &http2FancyWriter{}
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
// +build go1.8
|
||||
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// NewWrapResponseWriter wraps an http.ResponseWriter, returning a proxy that allows you to
|
||||
// hook into various parts of the response process.
|
||||
func NewWrapResponseWriter(w http.ResponseWriter) WrapResponseWriter {
|
||||
_, cn := w.(http.CloseNotifier)
|
||||
_, fl := w.(http.Flusher)
|
||||
_, hj := w.(http.Hijacker)
|
||||
_, rf := w.(io.ReaderFrom)
|
||||
_, ps := w.(http.Pusher)
|
||||
|
||||
bw := basicWriter{ResponseWriter: w}
|
||||
if cn && fl && hj && rf && !ps {
|
||||
return &httpFancyWriter{bw}
|
||||
}
|
||||
if cn && fl && !hj && !rf && ps {
|
||||
return &http2FancyWriter{bw}
|
||||
}
|
||||
if fl {
|
||||
return &flushWriter{bw}
|
||||
}
|
||||
return &bw
|
||||
}
|
||||
|
||||
// http2FancyWriter is a writer that additionally satisfies http.CloseNotifier,
|
||||
// http.Flusher, and http.Pusher. It exists for the common case of wrapping the
|
||||
// http.ResponseWriter that package http gives you, in order to make the proxied
|
||||
// object support the full method set of the proxied object.
|
||||
type http2FancyWriter struct {
|
||||
basicWriter
|
||||
}
|
||||
|
||||
func (f *http2FancyWriter) CloseNotify() <-chan bool {
|
||||
cn := f.basicWriter.ResponseWriter.(http.CloseNotifier)
|
||||
return cn.CloseNotify()
|
||||
}
|
||||
func (f *http2FancyWriter) Flush() {
|
||||
fl := f.basicWriter.ResponseWriter.(http.Flusher)
|
||||
fl.Flush()
|
||||
}
|
||||
func (f *http2FancyWriter) Push(target string, opts *http.PushOptions) error {
|
||||
ps := f.basicWriter.ResponseWriter.(http.Pusher)
|
||||
return ps.Push(target, opts)
|
||||
}
|
||||
|
||||
var _ http.CloseNotifier = &http2FancyWriter{}
|
||||
var _ http.Flusher = &http2FancyWriter{}
|
||||
var _ http.Pusher = &http2FancyWriter{}
|
||||
19
testdata/cert.pem
vendored
Normal file
19
testdata/cert.pem
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIC/zCCAeegAwIBAgIRANioW0Re7DtpT4qZpJU1iK8wDQYJKoZIhvcNAQELBQAw
|
||||
EjEQMA4GA1UEChMHQWNtZSBDbzAeFw0xNjEyMzExNDU0MzBaFw0xNzEyMzExNDU0
|
||||
MzBaMBIxEDAOBgNVBAoTB0FjbWUgQ28wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
|
||||
ggEKAoIBAQDpFfOsaXDYlL+ektfsqGYrSAsoTbe7zqjpow9nqUU4PmLRu2YMaaW8
|
||||
fAoneUnJxsJw7ql38+VMpphZUOmOWvsO7uV/lfnTIQfTwllHDdgAR5A11d84Zy/y
|
||||
TiNIFJduuaPtEhQs1dxPhU7TG8sEfFRhBoUDPv473akeGPNkVU756RVBYM6rUc3b
|
||||
YygD0PXGsQ2obrImbYUyyHH5YClCvGl1No57n3ugLqSSfwbgR3/Gw7kkGKy0PMOu
|
||||
TuHuJnTEmofJPkqEyFRVMlIAtfqFqJUfDHTOuQGWIUPnjDg+fqTI9EPJ+pElBqDQ
|
||||
IqW93BY5XePMdrTQc1h6xkduDfuLeA7TAgMBAAGjUDBOMA4GA1UdDwEB/wQEAwIF
|
||||
oDATBgNVHSUEDDAKBggrBgEFBQcDATAMBgNVHRMBAf8EAjAAMBkGA1UdEQQSMBCC
|
||||
DmxvY2FsaG9zdDo3MDcyMA0GCSqGSIb3DQEBCwUAA4IBAQDnsWmZdf7209A/XHUe
|
||||
xoONCbU8jaYFVoA+CN9J+3CASzrzTQ4fh9RJdm2FZuv4sWnb5c5hDN7H/M/nLcb0
|
||||
+uu7ACBGhd7yACYCQm/z3Pm3CY2BRIo0vCCRioGx+6J3CPGWFm0vHwNBge0iBOKC
|
||||
Wn+/YOlTDth/M3auHYlr7hdFmf57U4V/5iTr4wiKxwM9yMPcVRQF/1XpPd7A0VqM
|
||||
nFSEfDpFjrA7MvT3DrRqQGqF/ZXxDbro2nyki3YG8FwgKlFNVN9w55zNiriQ+WNA
|
||||
uz86lKg1FTc+m/R/0CD//7+7mme28N813EPVdV83TgxWNrfvAIRazkHE7YxETry0
|
||||
BJDg
|
||||
-----END CERTIFICATE-----
|
||||
27
testdata/key.pem
vendored
Normal file
27
testdata/key.pem
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEpAIBAAKCAQEA6RXzrGlw2JS/npLX7KhmK0gLKE23u86o6aMPZ6lFOD5i0btm
|
||||
DGmlvHwKJ3lJycbCcO6pd/PlTKaYWVDpjlr7Du7lf5X50yEH08JZRw3YAEeQNdXf
|
||||
OGcv8k4jSBSXbrmj7RIULNXcT4VO0xvLBHxUYQaFAz7+O92pHhjzZFVO+ekVQWDO
|
||||
q1HN22MoA9D1xrENqG6yJm2FMshx+WApQrxpdTaOe597oC6kkn8G4Ed/xsO5JBis
|
||||
tDzDrk7h7iZ0xJqHyT5KhMhUVTJSALX6haiVHwx0zrkBliFD54w4Pn6kyPRDyfqR
|
||||
JQag0CKlvdwWOV3jzHa00HNYesZHbg37i3gO0wIDAQABAoIBAFvqYDE5U1rVLctm
|
||||
tOeKcN/YhS3bl/zjvhCEUOrcAYPwdh+m+tMiRk1RzN9MISEE1GCcfQ/kiiPz/lga
|
||||
ZD/S+PYmlzH8/ouXlvKWzYYLm4ZgsinIsUIYzvuKfLdMB3uOkWpHmtUjcMGbHD57
|
||||
009tiAjK/WEOUkthWfOYe0KxsXczBn3PTAWZuiIkuA3RVWa7pCCFHUENkViP58wl
|
||||
Ky1hYKnunKPApRwuiC6qIT5ZOCSukdCCbkmRnj/x+P8+nsosu+1d85MNZb8uLRi0
|
||||
RzMmuOfOK2poDsrNHQX7itKlu7rzMJQc3+RauqIZovNe/BmSq+tYBLboXvUp18g/
|
||||
+VqKeEECgYEA/LaD1tJepzD/1lhgunFcnDjxsDJqLUpfR5eDMX1qhGJphuPBLOXS
|
||||
ushmVVjbVIn25Wxeoe4RYrZ6Tuu0FEJJgV44Lt42OOFgK2gyrCJpYmlxpRaw+7jc
|
||||
Dbp1Sh3/9VqMZjR/mQIzTnfOtS2n4Fk1Q53hdJn5Pn+uPMmMO4hF87sCgYEA7B4V
|
||||
BACsd6eqVxKkEMc72VLeYb0Ri0bl0FwbvIKXImppwA0tbMDmeA+6yhcRm23dhd5v
|
||||
cfNhJepRIzkM2CkhnazlsAbDoJPqb7/sbNzodtW1P0op7YIFYbrkcX4yOu9O1DNI
|
||||
Ij4PR8H1WcpPjhvr3q+iNO5agQX7bMQ1BnnJg8kCgYBA1tdm090DSrgpl81hqNpZ
|
||||
HucsDRNfAXkG1mIL3aDpzJJE0MTsrx7tW6Od/ElyHF/jp3V0WK/PQwCIpUMz+3n+
|
||||
nl0N8We6GmFhYb+2mLGvVVyaPgM04s5bG18ioCXfHtdtFcUzTfQ6CtVXeRpcnqbi
|
||||
7Ww+TY88sOfUouW/FIzWJwKBgQCsLauJhaw+fOc8I328NmywJzu+7g5TD9oZvHEF
|
||||
X/0xvYNr5rAPNANb3ayKHZRbURxOuEtwPtfCvEF6e+mf3y6COkgrumMBP5ue7cdM
|
||||
AzMJJQHMKxqz9TJTd+OJ10ptq4BCQTsCrVqbKxbs6RhmOnofoteX3Y/lsiULxXAd
|
||||
TsXh8QKBgQDQHosH8VoL7vIK+SqY5uoHAhMytSVNx4IaZZg4ho8oyjw12QXcidgV
|
||||
QJZQMdPEv8cAK78WcQdSthop+O/tu2cKLHyAmWmO3oU7gIQECui0aMXSqraO6Vde
|
||||
C5tqYlyLa7bHZS3AqrjRv9BRfwPKVkmBoYdA652rN/tE/K4UWsghnA==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
Loading…
Reference in a new issue