Skip to content

Instantly share code, notes, and snippets.

@bgbusted
Last active February 10, 2021 08:27
Show Gist options
  • Save bgbusted/698a76a42794364238ed0eb2b91e6186 to your computer and use it in GitHub Desktop.
Save bgbusted/698a76a42794364238ed0eb2b91e6186 to your computer and use it in GitHub Desktop.
main.go
package main
import (
"crypto/tls"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/http/cookiejar"
utls "gitlab.com/yawning/utls.git" //also works for source backups
//utls "CUSTOM/uTLS"
"golang.org/x/net/http2"
)
func main() {
cookieJar, _ := cookiejar.New(nil)
tr := &http2.Transport{
AllowHTTP: true,
DialTLS: func(network, addr string, cfg *tls.Config) (net.Conn, error) {
// Note that hardcoding the address is not necessary here. Only
// do that if you want to ignore the DNS lookup that already
// happened behind the scenes.
// proxyDialer, err := connectproxy.New(proxyUrl, proxy.Direct)
// tcpConn, err := proxyDialer.Dial("tcp", addr)
// if err != nil {
// return nil, err
// }
tcpConn, err := net.Dial("tcp", "http2.golang.org:443")
if err != nil {
fmt.Printf("net.Dial() failed: %+v\n", err)
return nil, err
}
config := utls.Config{ServerName: "http2.golang.org"}
tlsConn := utls.UClient(tcpConn, &config, utls.HelloChrome_83)
err = tlsConn.Handshake()
if err != nil {
return nil, fmt.Errorf("uTlsConn.Handshake() error: %w", err)
}
return tlsConn, nil
},
}
client := &http.Client{
Jar: cookieJar,
Transport: tr,
}
req, err := http.NewRequest("GET", "https://http2.golang.org/reqinfo", nil)
req.Header.Add("Host", "mail.google.com")
req.Header.Add("Cache-Control", "no-cache")
req.Header.Add("Content-Length", "216")
resp, err := client.Do(req)
if err != nil {
fmt.Println(err)
} else {
fmt.Println(resp.StatusCode)
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment