Fixed: https proxy doesn't works in Safari

This commit is contained in:
Dreamacro 2018-06-12 22:43:34 +08:00
parent 795557a2df
commit 20a3c231de

View file

@ -3,7 +3,6 @@ package proxy
import ( import (
"bufio" "bufio"
"bytes" "bytes"
"crypto/tls"
"fmt" "fmt"
"io" "io"
"net" "net"
@ -27,8 +26,6 @@ func NewHttpProxy(port string) {
handleHTTP(w, r) handleHTTP(w, r)
} }
}), }),
// Disable HTTP/2.
TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler)),
} }
log.Infof("HTTP proxy :%s", port) log.Infof("HTTP proxy :%s", port)
server.ListenAndServe() server.ListenAndServe()
@ -53,7 +50,6 @@ func handleHTTP(w http.ResponseWriter, r *http.Request) {
} }
func handleTunneling(w http.ResponseWriter, r *http.Request) { func handleTunneling(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
hijacker, ok := w.(http.Hijacker) hijacker, ok := w.(http.Hijacker)
if !ok { if !ok {
return return
@ -62,13 +58,14 @@ func handleTunneling(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
return return
} }
// w.WriteHeader(http.StatusOK) doesn't works in Safari
conn.Write([]byte("HTTP/1.1 200 OK\r\n\r\n"))
tun.Add(NewHttp(r.Host, conn, rw, []byte{})) tun.Add(NewHttp(r.Host, conn, rw, []byte{}))
} }
type HttpAdapter struct { type HttpAdapter struct {
addr *constant.Addr addr *constant.Addr
conn net.Conn conn net.Conn
rw *bufio.ReadWriter
r io.Reader r io.Reader
} }
@ -115,7 +112,6 @@ func NewHttp(host string, conn net.Conn, rw *bufio.ReadWriter, payload []byte) *
return &HttpAdapter{ return &HttpAdapter{
conn: conn, conn: conn,
addr: parseHttpAddr(host), addr: parseHttpAddr(host),
rw: rw,
r: r, r: r,
} }
} }