| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- package http3
- import (
- "net"
- "net/http/httptrace"
- "net/textproto"
- "time"
- tls "github.com/Psiphon-Labs/psiphon-tls"
- "github.com/Psiphon-Labs/quic-go"
- )
- func traceGetConn(trace *httptrace.ClientTrace, hostPort string) {
- if trace != nil && trace.GetConn != nil {
- trace.GetConn(hostPort)
- }
- }
- // fakeConn is a wrapper for quic.EarlyConnection
- // because the quic connection does not implement net.Conn.
- type fakeConn struct {
- conn quic.EarlyConnection
- }
- func (c *fakeConn) Close() error { panic("connection operation prohibited") }
- func (c *fakeConn) Read(p []byte) (int, error) { panic("connection operation prohibited") }
- func (c *fakeConn) Write(p []byte) (int, error) { panic("connection operation prohibited") }
- func (c *fakeConn) SetDeadline(t time.Time) error { panic("connection operation prohibited") }
- func (c *fakeConn) SetReadDeadline(t time.Time) error { panic("connection operation prohibited") }
- func (c *fakeConn) SetWriteDeadline(t time.Time) error { panic("connection operation prohibited") }
- func (c *fakeConn) RemoteAddr() net.Addr { return c.conn.RemoteAddr() }
- func (c *fakeConn) LocalAddr() net.Addr { return c.conn.LocalAddr() }
- func traceGotConn(trace *httptrace.ClientTrace, conn quic.EarlyConnection, reused bool) {
- if trace != nil && trace.GotConn != nil {
- trace.GotConn(httptrace.GotConnInfo{
- Conn: &fakeConn{conn: conn},
- Reused: reused,
- })
- }
- }
- func traceGotFirstResponseByte(trace *httptrace.ClientTrace) {
- if trace != nil && trace.GotFirstResponseByte != nil {
- trace.GotFirstResponseByte()
- }
- }
- func traceGot1xxResponse(trace *httptrace.ClientTrace, code int, header textproto.MIMEHeader) {
- if trace != nil && trace.Got1xxResponse != nil {
- trace.Got1xxResponse(code, header)
- }
- }
- func traceGot100Continue(trace *httptrace.ClientTrace) {
- if trace != nil && trace.Got100Continue != nil {
- trace.Got100Continue()
- }
- }
- func traceHasWroteHeaderField(trace *httptrace.ClientTrace) bool {
- return trace != nil && trace.WroteHeaderField != nil
- }
- func traceWroteHeaderField(trace *httptrace.ClientTrace, k, v string) {
- if trace != nil && trace.WroteHeaderField != nil {
- trace.WroteHeaderField(k, []string{v})
- }
- }
- func traceWroteHeaders(trace *httptrace.ClientTrace) {
- if trace != nil && trace.WroteHeaders != nil {
- trace.WroteHeaders()
- }
- }
- func traceWroteRequest(trace *httptrace.ClientTrace, err error) {
- if trace != nil && trace.WroteRequest != nil {
- trace.WroteRequest(httptrace.WroteRequestInfo{Err: err})
- }
- }
- func traceConnectStart(trace *httptrace.ClientTrace, network, addr string) {
- if trace != nil && trace.ConnectStart != nil {
- trace.ConnectStart(network, addr)
- }
- }
- func traceConnectDone(trace *httptrace.ClientTrace, network, addr string, err error) {
- if trace != nil && trace.ConnectDone != nil {
- trace.ConnectDone(network, addr, err)
- }
- }
- func traceTLSHandshakeStart(trace *httptrace.ClientTrace) {
- if trace != nil && trace.TLSHandshakeStart != nil {
- trace.TLSHandshakeStart()
- }
- }
- func traceTLSHandshakeDone(trace *httptrace.ClientTrace, state tls.ConnectionState, err error) {
- if trace != nil && trace.TLSHandshakeDone != nil {
- // [Psiphon]
- state := *tls.UnsafeFromConnectionState(&state)
- trace.TLSHandshakeDone(state, err)
- }
- }
|