Coder Social home page Coder Social logo

Comments (3)

uoosef avatar uoosef commented on July 19, 2024 2

i fixed this issue by removing h2 from chrom spec

package main

import (
	"context"
	"fmt"
	"log"
	"math/rand"
	"net"
	"time"

	"github.com/gorilla/websocket"
	tls "github.com/refraction-networking/utls"
)

var (
	randomFingerprint tls.ClientHelloID
)

func init() {
	modernFingerprints := []tls.ClientHelloID{
		tls.HelloChrome_Auto,
		tls.HelloFirefox_Auto,
		tls.HelloEdge_Auto,
		tls.HelloSafari_Auto,
		tls.HelloIOS_Auto,
	}
	randomFingerprint = modernFingerprints[rand.Intn(len(modernFingerprints))]
}

func main() {
	d := websocket.Dialer{
		NetDialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
			config := &tls.Config{
				InsecureSkipVerify: true,
			}
			dialConn, err := net.DialTimeout("tcp", addr, time.Second*20)
			if err != nil {
				return nil, err
			}
			client := tls.UClient(dialConn, config, tls.HelloCustom)

			spec, _ := tls.UTLSIdToSpec(randomFingerprint)
			for _, ext := range spec.Extensions {
				alpnExt, ok := ext.(*tls.ALPNExtension)
				if !ok {
					continue
				}

				alpnExt.AlpnProtocols = []string{"http/1.1"}
				fmt.Println("found")
			}

			client.ApplyPreset(&spec)
			return client, nil
		},
	}
	c, _, err := d.Dial("wss://ws.postman-echo.com/raw", nil)
	if err != nil {
		panic(err)
	}

	go func() {
		for {
			_, message, err := c.ReadMessage()
			if err != nil {
				log.Println("read:", err)
				return
			}
			log.Printf("recv: %s", message)
		}
	}()

	c.WriteMessage(websocket.TextMessage, []byte("echo!"))
	select {}
}

any idea why utls cant work with h2 ?

from utls.

gaukas avatar gaukas commented on July 19, 2024

This question has been answered for many times... But you're welcome.

The answer is short, that gorilla/websocket never implemented support for HTTP/2. The error is simply not on uTLS (unless supporting H2 is considered an error).

from utls.

gaukas avatar gaukas commented on July 19, 2024

Possibly duplicates #193.

from utls.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.