Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transport Connection Broken #64

Closed
mehtaabGill opened this issue Oct 22, 2020 · 1 comment
Closed

Transport Connection Broken #64

mehtaabGill opened this issue Oct 22, 2020 · 1 comment

Comments

@mehtaabGill
Copy link

Hello,

I am currently facing an issue with sending a GET request to https://http2.pro/api/v1.

The steps to reproduce:

  • git clone https://github.com/mehtaabGill/utls-test.git
  • cd utls-test
  • go get
  • go run main.go

The error i am receiving:

panic: Get "https://http2.pro/api/v1": net/http: HTTP/1.x transport connection broken: malformed HTTP status code "bad"

goroutine 1 [running]:
main.main()
        C:/Users/mehta/go/src/github.com/mehtaabGill/utls-test/main.go:23 +0x4f3
exit status 2

What I expected to see:
A proper JSON response which indicates I sent a request with a connection that supports HTTP2

Note - I am using the HelloChrome_83 ClientHelloID

@charkal233
Copy link

func CreateHTTPClient() http.Client {
	// initialize the http client
	client := http.Client{
		Transport: &http2.Transport{
			// this "tls.Config" comes from "crypto/tls"
			DialTLS: func(network, addr string, cfg *otls.Config) (net.Conn, error) {

				//initialize the tcp connection
				tcpConn, err := (&net.Dialer{}).Dial(network, addr)
				if err != nil {
					return nil, err
				}

				//initialize the conifg for tls
				config := tls.Config{
					ServerName: strings.Split(addr, ":")[0], //set the server name with the provided addr
				}

				//initialize a tls connection with the underlying tcop connection and config
				tlsConn := tls.UClient(tcpConn, &config, tls.HelloChrome_83)

				//start the tls handshake between servers
				err = tlsConn.Handshake()
				if err != nil {
					return nil, fmt.Errorf("uTlsConn.Handshake() error: %w", err)
				}

				return tlsConn, nil
			},
		},
	}

	return client
}

If you could confirm that server has h2 support, try to use http2.Transport in client

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants