Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: avoid importing net/http on wasm#449

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
paralin wants to merge2 commits intocoder:master
base:master
Choose a base branch
Loading
fromparalin:remove-net-http-wasm
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletionsws_js.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,6 @@ import (
"fmt"
"io"
"net"
"net/http"
"reflect"
"runtime"
"strings"
Expand DownExpand Up@@ -196,7 +195,7 @@ func (c *Conn) Ping(ctx context.Context) error {
// Write writes a message of the given type to the connection.
// Always non blocking.
func (c *Conn) Write(ctx context.Context, typ MessageType, p []byte) error {
err := c.write(ctx,typ, p)
err := c.write(typ, p)
if err != nil {
// Have to ensure the WebSocket is closed after a write error
// to match the Go API. It can only error if the message type
Expand All@@ -210,7 +209,7 @@ func (c *Conn) Write(ctx context.Context, typ MessageType, p []byte) error {
return nil
}

func (c *Conn) write(ctx context.Context,typ MessageType, p []byte) error {
func (c *Conn) write(typ MessageType, p []byte) error {
if c.isClosed() {
return net.ErrClosed
}
Expand DownExpand Up@@ -287,15 +286,15 @@ type DialOptions struct {
// The passed context bounds the maximum time spent waiting for the connection to open.
// The returned *http.Response is always nil or a mock. It's only in the signature
// to match the core API.
func Dial(ctx context.Context, url string, opts *DialOptions) (*Conn, *http.Response, error) {
func Dial(ctx context.Context, url string, opts *DialOptions) (*Conn, *struct{}, error) {
c, resp, err := dial(ctx, url, opts)
if err != nil {
return nil, nil, fmt.Errorf("failed to WebSocket dial %q: %w", url, err)
}
return c, resp, nil
}

func dial(ctx context.Context, url string, opts *DialOptions) (*Conn, *http.Response, error) {
func dial(ctx context.Context, url string, opts *DialOptions) (*Conn, *struct{}, error) {
if opts == nil {
opts = &DialOptions{}
}
Expand DownExpand Up@@ -324,9 +323,7 @@ func dial(ctx context.Context, url string, opts *DialOptions) (*Conn, *http.Resp
c.Close(StatusPolicyViolation, "dial timed out")
return nil, nil, ctx.Err()
case <-opench:
return c, &http.Response{
StatusCode: http.StatusSwitchingProtocols,
}, nil
return c, nil, nil
case <-c.closed:
return nil, nil, net.ErrClosed
}
Expand DownExpand Up@@ -442,7 +439,7 @@ type AcceptOptions struct {
}

// Accept is stubbed out for Wasm.
func Accept(whttp.ResponseWriter, r*http.Request, opts *AcceptOptions) (*Conn, error) {
func Accept(wany, rany, opts *AcceptOptions) (*Conn, error) {
return nil, errors.New("unimplemented")
}

Expand Down
5 changes: 2 additions & 3 deletionsws_js_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,6 @@ package websocket_test

import (
"context"
"net/http"
"os"
"testing"
"time"
Expand All@@ -18,14 +17,14 @@ func TestWasm(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()

c, resp, err := websocket.Dial(ctx, os.Getenv("WS_ECHO_SERVER_URL"), &websocket.DialOptions{
// NOTE: the response from websocket.Dial is a mock on js and not actually used.
c, _, err := websocket.Dial(ctx, os.Getenv("WS_ECHO_SERVER_URL"), &websocket.DialOptions{
Subprotocols: []string{"echo"},
})
assert.Success(t, err)
defer c.Close(websocket.StatusInternalError, "")

assert.Equal(t, "subprotocol", "echo", c.Subprotocol())
assert.Equal(t, "response code", http.StatusSwitchingProtocols, resp.StatusCode)

c.SetReadLimit(65536)
for i := 0; i < 10; i++ {
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp