6ccaae0573
Extract authenticate/probe-resistance to auth.go and roundTrip/forwarding to proxy.go, following the handler/http/ pattern. Export sentinel errors (ErrAuthFailed, ErrWrongConnType) for precise test assertions. Fix flushWriter panic recovery to handle non-string/non-error panics. Default HTTPS port to 443 when no port is specified in the Host header.
38 lines
513 B
Go
38 lines
513 B
Go
package http2
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
)
|
|
|
|
type flushWriter struct {
|
|
w io.Writer
|
|
}
|
|
|
|
func (fw flushWriter) Write(p []byte) (n int, err error) {
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
switch v := r.(type) {
|
|
case string:
|
|
err = errors.New(v)
|
|
case error:
|
|
err = v
|
|
default:
|
|
err = fmt.Errorf("%v", v)
|
|
}
|
|
}
|
|
}()
|
|
|
|
n, err = fw.w.Write(p)
|
|
if err != nil {
|
|
// log.Log("flush writer:", err)
|
|
return
|
|
}
|
|
if f, ok := fw.w.(http.Flusher); ok {
|
|
f.Flush()
|
|
}
|
|
return
|
|
}
|