Faster server implementation.
This commit is contained in:
parent
d5045e5a1d
commit
0badc6c3d7
3 changed files with 15 additions and 12 deletions
2
go.mod
2
go.mod
|
@ -2,4 +2,4 @@ module github.com/FireMasterK/http3-ytproxy/v2
|
|||
|
||||
go 1.15
|
||||
|
||||
require github.com/lucas-clemente/quic-go v0.18.1
|
||||
require github.com/lucas-clemente/quic-go v0.19.3
|
||||
|
|
12
go.sum
12
go.sum
|
@ -72,16 +72,16 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
|||
github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/lucas-clemente/quic-go v0.18.1 h1:DMR7guC0NtVS8zNZR3IO7NARZvZygkSC56GGtC6cyys=
|
||||
github.com/lucas-clemente/quic-go v0.18.1/go.mod h1:yXttHsSNxQi8AWijC/vLP+OJczXqzHSOcJrM5ITUlCg=
|
||||
github.com/lucas-clemente/quic-go v0.19.3 h1:eCDQqvGBB+kCTkA0XrAFtNe81FMa0/fn4QSoeAbmiF4=
|
||||
github.com/lucas-clemente/quic-go v0.19.3/go.mod h1:ADXpNbTQjq1hIzCpB+y/k5iz4n4z4IwqoLb94Kh5Hu8=
|
||||
github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI=
|
||||
github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/marten-seemann/qpack v0.2.0 h1:/r1rhZoOmgxVKBqPNnYilZBDEyw+6OUHCbBzA5jc2y0=
|
||||
github.com/marten-seemann/qpack v0.2.0/go.mod h1:F7Gl5L1jIgN1D11ucXefiuJS9UMVP2opoCp2jDKb7wc=
|
||||
github.com/marten-seemann/qpack v0.2.1 h1:jvTsT/HpCn2UZJdP+UUB53FfUUgeOyG5K1ns0OJOGVs=
|
||||
github.com/marten-seemann/qpack v0.2.1/go.mod h1:F7Gl5L1jIgN1D11ucXefiuJS9UMVP2opoCp2jDKb7wc=
|
||||
github.com/marten-seemann/qtls v0.10.0 h1:ECsuYUKalRL240rRD4Ri33ISb7kAQ3qGDlrrl55b2pc=
|
||||
github.com/marten-seemann/qtls v0.10.0/go.mod h1:UvMd1oaYDACI99/oZUYLzMCkBXQVT0aGm99sJhbT8hs=
|
||||
github.com/marten-seemann/qtls-go1-15 v0.1.0 h1:i/YPXVxz8q9umso/5y474CNcHmTpA+5DH+mFPjx6PZg=
|
||||
github.com/marten-seemann/qtls-go1-15 v0.1.0/go.mod h1:GyFwywLKkRt+6mfU99csTEY1joMZz5vmB1WNZH3P81I=
|
||||
github.com/marten-seemann/qtls-go1-15 v0.1.1 h1:LIH6K34bPVttyXnUWixk0bzH6/N07VxbSabxn5A5gZQ=
|
||||
github.com/marten-seemann/qtls-go1-15 v0.1.1/go.mod h1:GyFwywLKkRt+6mfU99csTEY1joMZz5vmB1WNZH3P81I=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
|
|
13
main.go
13
main.go
|
@ -25,7 +25,9 @@ var h2client = &http.Client{}
|
|||
// user agent to use
|
||||
var ua = "Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101"
|
||||
|
||||
func genericHTTPProxy(w http.ResponseWriter, req *http.Request) {
|
||||
type requesthandler struct{}
|
||||
|
||||
func (*requesthandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
|
||||
q := req.URL.Query()
|
||||
host := q.Get("host")
|
||||
|
@ -81,12 +83,13 @@ func genericHTTPProxy(w http.ResponseWriter, req *http.Request) {
|
|||
log.Panic(err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
copyHeaders(resp.Header, w.Header())
|
||||
|
||||
w.WriteHeader(resp.StatusCode)
|
||||
|
||||
io.Copy(w, resp.Body)
|
||||
resp.Body.Close()
|
||||
}
|
||||
|
||||
func copyHeaders(from http.Header, to http.Header) {
|
||||
|
@ -135,15 +138,15 @@ func getBestThumbnail(path string) (newpath string) {
|
|||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/", genericHTTPProxy)
|
||||
socket := "socket" + string(os.PathSeparator) + "http-proxy.sock"
|
||||
syscall.Unlink(socket)
|
||||
listener, err := net.Listen("unix", socket)
|
||||
if err != nil {
|
||||
fmt.Println("Failed to bind to UDS, falling back to TCP/IP")
|
||||
fmt.Println(err.Error())
|
||||
http.ListenAndServe(":8080", nil)
|
||||
http.ListenAndServe(":8080", &requesthandler{})
|
||||
} else {
|
||||
http.Serve(listener, nil)
|
||||
defer listener.Close()
|
||||
http.Serve(listener, &requesthandler{})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue