github.com/iDigitalFlame/xmt@v0.5.4/com/wc2/c_compat.go (about)

     1  //go:build !go1.13
     2  // +build !go1.13
     3  
     4  // Copyright (C) 2020 - 2023 iDigitalFlame
     5  //
     6  // This program is free software: you can redistribute it and/or modify
     7  // it under the terms of the GNU General Public License as published by
     8  // the Free Software Foundation, either version 3 of the License, or
     9  // any later version.
    10  //
    11  // This program is distributed in the hope that it will be useful,
    12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  // GNU General Public License for more details.
    15  //
    16  // You should have received a copy of the GNU General Public License
    17  // along with this program.  If not, see <https://www.gnu.org/licenses/>.
    18  //
    19  
    20  package wc2
    21  
    22  import (
    23  	"context"
    24  	"net"
    25  	"net/http"
    26  	"time"
    27  
    28  	"github.com/iDigitalFlame/xmt/device"
    29  )
    30  
    31  type maskedConn struct {
    32  	net.Conn
    33  }
    34  
    35  func (maskedConn) Close() error {
    36  	return nil
    37  }
    38  func maskConn(c net.Conn) net.Conn {
    39  	// NOTE(dij): Until go1.12, the HTTP library doesn't understand websockets
    40  	//            so it tries to close ALL net.Conn's after each request completes.
    41  	//            Let's make sure that doesn't happen so we can use it.
    42  	return maskedConn{c}
    43  }
    44  func (t *transport) hook(x *http.Transport) {
    45  	x.DialTLS = t.dialTLS
    46  	x.DialContext = t.dialContext
    47  }
    48  func newRequest(x context.Context) *http.Request {
    49  	r, _ := http.NewRequest(http.MethodGet, "", nil)
    50  	return r.WithContext(x)
    51  }
    52  func newTransport(d time.Duration) *http.Transport {
    53  	return &http.Transport{
    54  		Proxy:                 device.Proxy,
    55  		MaxIdleConns:          0,
    56  		IdleConnTimeout:       0,
    57  		DisableKeepAlives:     true,
    58  		MaxIdleConnsPerHost:   0,
    59  		TLSHandshakeTimeout:   d,
    60  		ExpectContinueTimeout: d,
    61  		ResponseHeaderTimeout: d,
    62  	}
    63  }
    64  func (t *transport) dialTLS(_, a string) (net.Conn, error) {
    65  	return t.dialTLSContext(context.Background(), "", a)
    66  }
    67  func baseContext(_ *listener, _ func(net.Listener) context.Context) {}