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

v1.8.8 #256

Merged
merged 116 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
b453d3e
Move all Wasm related code into ws_js.go
nhooyr May 18, 2020
17cf0fe
Disable compression by default
nhooyr May 18, 2020
de8e29b
Fix tests taking too long and switch to t.Cleanup
nhooyr May 18, 2020
1695216
Add ping example
nhooyr May 18, 2020
0a61ffe
Make SetDeadline on NetConn not always close Conn
nhooyr May 18, 2020
aa4d85f
Merge pull request #240 from nhooyr/restructure
nhooyr May 19, 2020
15a1523
ci/fmt.sh: Cleanup
nhooyr Jul 4, 2020
493ebbe
netconn.go: Prevent timer leakage (#255)
nhooyr Jul 5, 2020
897a573
write.go: Fix deadlock in writeFrame (#253)
nhooyr Jul 5, 2020
fdc4079
Clone options (#259)
abursavich Sep 24, 2020
06beb14
Merge branch 'master' into merge-master
nhooyr Jan 9, 2021
fe1020d
Fix incorrect &*var clones
nhooyr Jan 9, 2021
e4fee52
ci/test.sh: Work with BSD sed
nhooyr Jan 9, 2021
a8e475c
Merge pull request #277 from nhooyr/merge-master
nhooyr Jan 9, 2021
3b20a49
Add back documentation on separate idle and read timeout
nhooyr Jan 9, 2021
29f527b
Remove ExampleGrace for now to avoid confusion
nhooyr Jan 9, 2021
085d46c
Document context expirations wart
nhooyr Jan 9, 2021
ea87744
netconn: Disable read limit on WebSocket
nhooyr Jul 4, 2020
11af7f8
netconn: Add test for disabled read limit
nhooyr Jan 9, 2021
642a013
Merge pull request #254 from nhooyr/netconn-readlimit
nhooyr Jan 9, 2021
482f584
netconn.go: Cleanup contexts on close
nhooyr Jan 9, 2021
29251d0
accept.go: Improve unauthorized origin error message
nhooyr Jan 9, 2021
7c0c047
Fix formatting
nhooyr Jan 9, 2021
6840778
README.md: Update coverage
nhooyr Jan 9, 2021
65dfbdd
wasm: Add dial timeout test
nhooyr Jan 9, 2021
7fd6136
Fix dial panic when ctx is nil
guseggert Jan 30, 2023
e2bb5be
Migrate from deprecated `io/ioutil`
keystroke3 Feb 25, 2023
54809d6
Update err message when dial ctx is nil
guseggert Mar 7, 2023
6ead6aa
autobahn_test: Use docker to avoid issues with python2 EOL
nhooyr Apr 7, 2023
7c87cb5
Fix DOS attack from malicious pongs
nhooyr Sep 28, 2023
b8f6512
Fix grammar (#295)
arthmis Apr 10, 2021
9e84c89
README.md: Add note
nhooyr Dec 13, 2022
de6965b
REAME: Update note
nhooyr Dec 13, 2022
9e7b1d5
README: Further update
nhooyr Dec 13, 2022
7a37b6a
Merge branch 'master' into dev
nhooyr Sep 28, 2023
5dd228a
compress.go: Add back comment about Safari compat layer being disabled
nhooyr Sep 28, 2023
b9a4d42
LICENSE.txt: Switch to OpenBSD's license
nhooyr Sep 28, 2023
a374f19
.github: Delete CODEOWNERS
nhooyr Sep 28, 2023
c45cd4c
ci/container: Fix for newer Go
nhooyr Sep 28, 2023
118ea68
ci: Fixes
nhooyr Sep 28, 2023
8d3d892
Update Go module version to 1.18
Jacalz Mar 12, 2023
4188bcf
go.mod: Regenerate
nhooyr Oct 10, 2023
1c90f47
ci.yml: Fix
nhooyr Oct 10, 2023
2a5a566
go.mod: Upgrade to Go 1.19
nhooyr Oct 10, 2023
e1e65ad
daily.yml: Add to run AUTOBAHN tests daily
nhooyr Oct 10, 2023
75bf907
autobahn_test.go: Pull image before starting container
nhooyr Oct 10, 2023
91423a9
Merge pull request #371 from keystroke3/master
nhooyr Oct 10, 2023
4ab2f54
conn_test: Remove ioutil
nhooyr Oct 10, 2023
e9d0881
Use net.ErrClosed
emersion May 19, 2021
7ce08e9
Merge pull request #303 from emersion/err-closed
nhooyr Oct 13, 2023
693fac9
Merge pull request #365 from guseggert/master
nhooyr Oct 13, 2023
e305027
dial.go: Clarify http.NewRequestWithContext error
nhooyr Oct 13, 2023
ac38512
wspb: Remove
nhooyr Oct 13, 2023
9b5a15b
close_goXXX.go: fmt
nhooyr Oct 13, 2023
a633a10
lint.sh: Pass
nhooyr Oct 13, 2023
3f26c9f
wsjson: Write messages in a single frame always
nhooyr Oct 13, 2023
f7bed7c
Extend DialOptions to allow Host header override
bendiscz Apr 28, 2022
2f44d4e
Merge pull request #336 from bendiscz/client-host-override
nhooyr Oct 13, 2023
9873274
wsjson: fmt
nhooyr Oct 13, 2023
fecf26c
netconn.go: Return real remote and local address where possible
photostorm Apr 24, 2021
61942a4
Merge pull request #299 from photostorm/net-addr
nhooyr Oct 13, 2023
5793e7d
internal/util: golint
nhooyr Oct 13, 2023
2598ea2
Remove third party dependencies from go.mod and go.sum
nhooyr Oct 13, 2023
b4b86b9
dial.go: Use timeout on HTTPClient properly
nhooyr Oct 13, 2023
a6b9464
conn: Add noCopy
nhooyr Oct 13, 2023
4e15d75
ci/bench.sh: Add
nhooyr Oct 13, 2023
a02cbef
compress.go: Fix context takeover
nhooyr Oct 13, 2023
81afa8a
netconn: Avoid returning 0, nil in NetConn.Read
nhooyr Oct 13, 2023
136f954
Client allows server to specify server_max_window_bits
abursavich Sep 9, 2020
2291d83
Server allows client to specify server_max_window_bits=15
abursavich Sep 9, 2020
711aa3f
Server selects first acceptable compression offer
abursavich Sep 9, 2020
d6b342b
Remove x-webkit-deflate-frame dead code
abursavich Sep 9, 2020
97d7f90
Merge pull request #258 from abursavich/compression
nhooyr Oct 13, 2023
a975390
internal/*/go.mod: Use go 1.19 too
nhooyr Oct 13, 2023
1dbc141
write: Zero alloc writes with Writer
nhooyr Oct 14, 2023
a94999f
close: Implement CloseNow
nhooyr Oct 14, 2023
e314da6
dial: Redirect wss/ws correctly by modifying the http client
nhooyr Oct 14, 2023
249edb2
dial_test: Add TestDialViaProxy
nhooyr Oct 19, 2023
818579b
TestDialViaProxy: Fix bug in forward proxy
nhooyr Oct 19, 2023
20b8838
ci: Add dev to daily
nhooyr Oct 19, 2023
591ff8e
accept.go: Comment typo
nhooyr Oct 19, 2023
64ce009
conn: Return net.ErrClosed whenever appropriate
nhooyr Oct 19, 2023
1a344a4
Reject invalid "Sec-WebSocket-Key" headers from clients
Emyrk Dec 20, 2022
f46da9a
Remove build tag at top of files
Emyrk Dec 20, 2022
3233cb5
Remove all leading and trailing whitespace
Emyrk Dec 20, 2022
309e088
Handle multiple sec-websocket-keys
Emyrk Dec 20, 2022
305eab9
misc: Format and compile #360
nhooyr Oct 19, 2023
10137fa
Merge pull request #360 from Emyrk/emyrk/Sec-WebSocket-Key
nhooyr Oct 19, 2023
e361137
wsjs: Register OnError
nhooyr Oct 19, 2023
8abed3a
close.go: Remove unnecessary log.Printf call
nhooyr Oct 19, 2023
e4879ab
conn_test: Add TestConcurrentClosePing
univerio May 25, 2023
28c6709
conn_test.go: Fix TestConcurrentClosePing
nhooyr Oct 19, 2023
6cec2ca
close.go: Fix mid read close
nhooyr Oct 19, 2023
5fe95bb
write.go: Fix potential writeFrame deadlock
nhooyr Oct 19, 2023
308a8e2
autobahn_test.go: Fix TODOs
nhooyr Oct 19, 2023
d22d1f3
ci/test.sh: Always benchmark
nhooyr Oct 19, 2023
50952d7
compress.go: Rewrite compression docs
nhooyr Oct 19, 2023
9d9c971
Update docs
nhooyr Oct 19, 2023
25a5ca4
netconn.go: Fix panic on zero or negative deadline durations
nhooyr Oct 19, 2023
cdeb980
ws_js.go: Add CloseNow
nhooyr Oct 19, 2023
fb3b083
close.go: Drop support for Go 1.13
nhooyr Oct 19, 2023
9fdcb5d
Misc fixes
nhooyr Oct 19, 2023
db79f72
Update README.md
nhooyr Oct 19, 2023
108d137
Update README.md
nhooyr Oct 19, 2023
e6a7e0e
main_test.go: Add to detect goroutine leaks
nhooyr Oct 19, 2023
6ed989a
Ensure no goroutines leak after Close
nhooyr Oct 19, 2023
d7a55cf
Ensure no goroutines leak after Close in a cleaner way
nhooyr Oct 19, 2023
7b1a6bb
README.md formatting fix
nhooyr Oct 19, 2023
d91a212
wsjs: Ensure no goroutines leak after Close
nhooyr Oct 19, 2023
0caa997
Another README.md update
nhooyr Oct 19, 2023
7d8ddbc
Fix in README.md
nhooyr Oct 19, 2023
535fd2c
go.sum: Delete
nhooyr Oct 19, 2023
63c0405
ci/fmt.sh: Tidy internal module dependencies
nhooyr Oct 19, 2023
7ada249
Fix typo in README.md
nhooyr Oct 19, 2023
ff3ea39
ci/lint.sh: Remove golint
nhooyr Oct 19, 2023
af0fd9d
examples/chat: Fix race condition
nhooyr Oct 19, 2023
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
1 change: 0 additions & 1 deletion .github/CODEOWNERS

This file was deleted.

39 changes: 0 additions & 39 deletions .github/workflows/ci.yaml

This file was deleted.

47 changes: 47 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: ci
on: [push, pull_request]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

jobs:
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: ./go.mod
- run: ./ci/fmt.sh

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: go version
- uses: actions/setup-go@v4
with:
go-version-file: ./go.mod
- run: ./ci/lint.sh

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: ./go.mod
- run: ./ci/test.sh
- uses: actions/upload-artifact@v3
with:
name: coverage.html
path: ./ci/out/coverage.html

bench:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: ./go.mod
- run: ./ci/bench.sh
54 changes: 54 additions & 0 deletions .github/workflows/daily.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: daily
on:
workflow_dispatch:
schedule:
- cron: '42 0 * * *' # daily at 00:42
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true

jobs:
bench:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: ./go.mod
- run: AUTOBAHN=1 ./ci/bench.sh
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: ./go.mod
- run: AUTOBAHN=1 ./ci/test.sh
- uses: actions/upload-artifact@v3
with:
name: coverage.html
path: ./ci/out/coverage.html
bench-dev:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: dev
- uses: actions/setup-go@v4
with:
go-version-file: ./go.mod
- run: AUTOBAHN=1 ./ci/bench.sh
test-dev:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: dev
- uses: actions/setup-go@v4
with:
go-version-file: ./go.mod
- run: AUTOBAHN=1 ./ci/test.sh
- uses: actions/upload-artifact@v3
with:
name: coverage.html
path: ./ci/out/coverage.html
1 change: 0 additions & 1 deletion .gitignore

This file was deleted.

34 changes: 13 additions & 21 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
MIT License

Copyright (c) 2018 Anmol Sethi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Copyright (c) 2023 Anmol Sethi <[email protected]>

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
53 changes: 34 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
# websocket

[![godoc](https://godoc.org/nhooyr.io/websocket?status.svg)](https://pkg.go.dev/nhooyr.io/websocket)
[![coverage](https://img.shields.io/badge/coverage-88%25-success)](https://nhooyrio-websocket-coverage.netlify.app)
[![coverage](https://img.shields.io/badge/coverage-91%25-success)](https://nhooyr.io/websocket/coverage.html)

websocket is a minimal and idiomatic WebSocket library for Go.

> **note**: I haven't been responsive for questions/reports on the issue tracker but I do
> read through and there are no outstanding bugs. There are certainly some nice to haves
> that I should merge in/figure out but nothing critical. I haven't given up on adding new
> features and cleaning up the code further, just been busy. Should anything critical
> arise, I will fix it.

## Install

```bash
```sh
go get nhooyr.io/websocket
```

Expand All @@ -22,26 +16,37 @@ go get nhooyr.io/websocket
- Minimal and idiomatic API
- First class [context.Context](https://blog.golang.org/context) support
- Fully passes the WebSocket [autobahn-testsuite](https://github.com/crossbario/autobahn-testsuite)
- [Single dependency](https://pkg.go.dev/nhooyr.io/websocket?tab=imports)
- JSON and protobuf helpers in the [wsjson](https://pkg.go.dev/nhooyr.io/websocket/wsjson) and [wspb](https://pkg.go.dev/nhooyr.io/websocket/wspb) subpackages
- [Zero dependencies](https://pkg.go.dev/nhooyr.io/websocket?tab=imports)
- JSON helpers in the [wsjson](https://pkg.go.dev/nhooyr.io/websocket/wsjson) subpackage
- Zero alloc reads and writes
- Concurrent writes
- [Close handshake](https://pkg.go.dev/nhooyr.io/websocket#Conn.Close)
- [net.Conn](https://pkg.go.dev/nhooyr.io/websocket#NetConn) wrapper
- [Ping pong](https://pkg.go.dev/nhooyr.io/websocket#Conn.Ping) API
- [RFC 7692](https://tools.ietf.org/html/rfc7692) permessage-deflate compression
- [CloseRead](https://pkg.go.dev/nhooyr.io/websocket#Conn.CloseRead) helper for write only connections
- Compile to [Wasm](https://pkg.go.dev/nhooyr.io/websocket#hdr-Wasm)

## Roadmap

See GitHub issues for minor issues but the major future enhancements are:

- [ ] Perfect examples [#217](https://github.com/nhooyr/websocket/issues/217)
- [ ] wstest.Pipe for in memory testing [#340](https://github.com/nhooyr/websocket/issues/340)
- [ ] Ping pong heartbeat helper [#267](https://github.com/nhooyr/websocket/issues/267)
- [ ] Ping pong instrumentation callbacks [#246](https://github.com/nhooyr/websocket/issues/246)
- [ ] Graceful shutdown helpers [#209](https://github.com/nhooyr/websocket/issues/209)
- [ ] Assembly for WebSocket masking [#16](https://github.com/nhooyr/websocket/issues/16)
- WIP at [#326](https://github.com/nhooyr/websocket/pull/326), about 3x faster
- [ ] HTTP/2 [#4](https://github.com/nhooyr/websocket/issues/4)
- [ ] The holy grail [#402](https://github.com/nhooyr/websocket/issues/402)

## Examples

For a production quality example that demonstrates the complete API, see the
[echo example](./examples/echo).
[echo example](./internal/examples/echo).

For a full stack example, see the [chat example](./examples/chat).
For a full stack example, see the [chat example](./internal/examples/chat).

### Server

Expand All @@ -51,7 +56,7 @@ http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
if err != nil {
// ...
}
defer c.Close(websocket.StatusInternalError, "the sky is falling")
defer c.CloseNow()

ctx, cancel := context.WithTimeout(r.Context(), time.Second*10)
defer cancel()
Expand All @@ -78,7 +83,7 @@ c, _, err := websocket.Dial(ctx, "ws://localhost:8080", nil)
if err != nil {
// ...
}
defer c.Close(websocket.StatusInternalError, "the sky is falling")
defer c.CloseNow()

err = wsjson.Write(ctx, c, "hi")
if err != nil {
Expand Down Expand Up @@ -113,14 +118,13 @@ Advantages of nhooyr.io/websocket:
- Idiomatic [ping pong](https://pkg.go.dev/nhooyr.io/websocket#Conn.Ping) API
- Gorilla requires registering a pong callback before sending a Ping
- Can target Wasm ([gorilla/websocket#432](https://github.com/gorilla/websocket/issues/432))
- Transparent message buffer reuse with [wsjson](https://pkg.go.dev/nhooyr.io/websocket/wsjson) and [wspb](https://pkg.go.dev/nhooyr.io/websocket/wspb) subpackages
- Transparent message buffer reuse with [wsjson](https://pkg.go.dev/nhooyr.io/websocket/wsjson) subpackage
- [1.75x](https://github.com/nhooyr/websocket/releases/tag/v1.7.4) faster WebSocket masking implementation in pure Go
- Gorilla's implementation is slower and uses [unsafe](https://golang.org/pkg/unsafe/).
Soon we'll have assembly and be 3x faster [#326](https://github.com/nhooyr/websocket/pull/326)
- Full [permessage-deflate](https://tools.ietf.org/html/rfc7692) compression extension support
- Gorilla only supports no context takeover mode
- We use [klauspost/compress](https://github.com/klauspost/compress) for much lower memory usage ([gorilla/websocket#203](https://github.com/gorilla/websocket/issues/203))
- [CloseRead](https://pkg.go.dev/nhooyr.io/websocket#Conn.CloseRead) helper ([gorilla/websocket#492](https://github.com/gorilla/websocket/issues/492))
- Actively maintained ([gorilla/websocket#370](https://github.com/gorilla/websocket/issues/370))
- [CloseRead](https://pkg.go.dev/nhooyr.io/websocket#Conn.CloseRead) helper for write only connections ([gorilla/websocket#492](https://github.com/gorilla/websocket/issues/492))

#### golang.org/x/net/websocket

Expand All @@ -135,4 +139,15 @@ to nhooyr.io/websocket.
[gobwas/ws](https://github.com/gobwas/ws) has an extremely flexible API that allows it to be used
in an event driven style for performance. See the author's [blog post](https://medium.freecodecamp.org/million-websockets-and-go-cc58418460bb).

However when writing idiomatic Go, nhooyr.io/websocket will be faster and easier to use.
However it is quite bloated. See https://pkg.go.dev/github.com/gobwas/ws

When writing idiomatic Go, nhooyr.io/websocket will be faster and easier to use.

#### lesismal/nbio

[lesismal/nbio](https://github.com/lesismal/nbio) is similar to gobwas/ws in that the API is
event driven for performance reasons.

However it is quite bloated. See https://pkg.go.dev/github.com/lesismal/nbio

When writing idiomatic Go, nhooyr.io/websocket will be faster and easier to use.
Loading
Loading