wasmws

package module
v0.0.0-...-3cb4638 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2023 License: MPL-2.0 Imports: 6 Imported by: 0

README

声明: 本项目拷贝自 tarndt的wasmws 仅针对项目使用中遇到跨域请求问题(err: not authorized for Host)稍微做了一些修改 (我不确定该错误是否是由我的配置错误引起的)

​ 我的做法是在函数NewWebSocketListener()中传入了websocket.AcceptOptions 并在websocket.Accept时使用该opts

示例demo的运行方法:

demo/server目录下使用:

make run

Declaration: This project is a copy of tarndt's wasmws for the purpose of solving the cross-domain request problem (err: not authorized for Host) with some modifications (I'm not sure if the error is caused by my configuration error).

My approach is to pass websocket.AcceptOptions to the function NewWebSocketListener() and use it in websocket.Accept().

Example demo running method:

In the demo/server directory, use:

make run

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type WebSockListener

type WebSockListener struct {
	// contains filtered or unexported fields
}

WebSockListener implements net.Listener and provides connections that are incoming websocket connections

func NewWebSocketListener

func NewWebSocketListener(ctx context.Context, opts *websocket.AcceptOptions) *WebSockListener

NewWebSocketListener constructs a new WebSockListener, the provided context is for the lifetime of the listener. 初始化的时候加了一个 websocket.Accept时的 opts 参数

// websocket.AcceptOptions 参数
type AcceptOptions struct {
	Subprotocols         []string 			// 支持的子协议
	InsecureSkipVerify   bool				// 是否跳过 SSL/TLS 证书的验证
	OriginPatterns       []string			// 跨域请求设置  []string("*")表示允许所有来源 也可以[]string{"*://example.com", "http://example*"} 满足一个即可访问
	CompressionMode      CompressionMode	// 压缩模式 websocket.Compression... 有三种 详见websocket源码注释
	CompressionThreshold int				// 压缩数据的最低字节数阈值
}

func (*WebSockListener) Accept

func (wsl *WebSockListener) Accept() (net.Conn, error)

Accept fulfills the net.Listener interface and returns net.Conn that are incoming websockets

func (*WebSockListener) Addr

func (wsl *WebSockListener) Addr() net.Addr

RemoteAddr returns a dummy websocket address to satisfy net.Listener

func (*WebSockListener) Close

func (wsl *WebSockListener) Close() error

Close closes the listener

func (*WebSockListener) ServeHTTP

func (wsl *WebSockListener) ServeHTTP(wtr http.ResponseWriter, req *http.Request)

ServeHTTP is a method that is mean to be used as http.HandlerFunc to accept inbound HTTP requests that are websocket connections

Directories

Path Synopsis
demo

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL