Commit Graph

337 Commits

Author SHA1 Message Date
rfyiamcool d293aa53e1 feat: format message type
Signed-off-by: rfyiamcool <rfyiamcool@163.com>
2024-02-13 23:01:06 -05:00
rfyiamcool 0cfb2cafd0 feat: format message type
Signed-off-by: rfyiamcool <rfyiamcool@163.com>
2024-02-13 23:01:06 -05:00
rfyiamcool 316861440d fix: lint example
Signed-off-by: rfyiamcool <rfyiamcool@163.com>
2024-02-13 22:50:58 -05:00
rfyiamcool d08ee1ad9b perf: reduce timer in write_control
Signed-off-by: rfyiamcool <rfyiamcool@163.com>
2024-01-22 22:58:11 -05:00
rfyiamcool d15aba1e61 perf: reduce timer in write_control
Signed-off-by: rfyiamcool <rfyiamcool@163.com>
2024-01-22 22:58:11 -05:00
Kenjiro Nakayama cf50a3efbb Revert "Print log message"
This reverts commit 6db907caed.
2024-01-21 23:02:08 -05:00
Kenjiro Nakayama 7d5b8cce7e Print log message 2024-01-21 23:02:08 -05:00
Kenjiro Nakayama 4965080703 Do not return error in SetCloseHandler 2024-01-21 23:02:08 -05:00
Kenjiro Nakayama 9a2140519a Do not handle network error in SetCloseHandler()
The 666c197 added an error handling in `SetCloseHandler()` and peer
stops getting `CloseError` when network issue like `write: broken
pipe` happens because the close handle returns the error.

Hence this patch changes to skip network error handling.
2024-01-21 23:02:08 -05:00
merlin 0f0acefeac fix: don't use errors.ErrUnsupported, it's available only since go1.21 2024-01-21 22:52:10 -05:00
merlin 1e975a03ce use http.ResposnseController 2024-01-21 22:52:10 -05:00
merlin 4a5e66f763 make tests parallel 2024-01-21 22:46:55 -05:00
Alan Xu 871f6bbc74
docs(echoreadall): fix function echoReadAll comment (#881)
As of Go 1.16, ioutil.ReadAll was deprecated.
2024-01-18 16:21:03 +10:00
Brendan Creane dcea2f088c Remove noisy printf in NextReader() 2023-12-10 23:08:54 -05:00
fengyun.rui 01b0aaed92
fix: add comment for the readBufferSize and writeBufferSize (#869)
### summary

😅 Every time I use `gorilla/websocket`, I need to look at the source
code and find the default size for readBufferSize and writeBufferSize.

I think the default value should be written in the comment.

Signed-off-by: rfyiamcool <rfyiamcool@163.com>
Co-authored-by: Alex Vulaj <ajvulaj@gmail.com>
2023-12-07 00:01:23 -05:00
fengyun.rui 286c896192
fix: replace ioutil.readfile with os.readfile (#868)
### summay

`ioutil.ReadFile` is Deprecated, As of Go 1.16, this function simply
calls [os.ReadFile].

Signed-off-by: rfyiamcool <rfyiamcool@163.com>
2023-12-06 23:58:12 -05:00
Henrik Hautakoski 6f5d2139f4
conn.go: default close handler should not return ErrCloseSent. (#865)
<!--
For Work In Progress Pull Requests, please use the Draft PR feature,
see https://github.blog/2019-02-14-introducing-draft-pull-requests/ for
further details.

     For a timely review/response, please avoid force-pushing additional
     commits if your PR already received reviews or comments.

     Before submitting a Pull Request, please ensure that you have:
- 📖 Read the Contributing guide:
https://github.com/gorilla/.github/blob/main/CONTRIBUTING.md
- 📖 Read the Code of Conduct:
https://github.com/gorilla/.github/blob/main/CODE_OF_CONDUCT.md

     - Provide tests for your changes.
     - Use descriptive commit messages.
	 - Comment your code where appropriate.
	 - Squash your commits
     - Update any related documentation.

     - Add gorilla/pull-request-reviewers as a Reviewer
-->

## What type of PR is this? (check all applicable)

- [ ] Refactor
- [ ] Feature
- [x] Bug Fix
- [ ] Optimization
- [ ] Documentation Update
- [ ] Go Version Update
- [ ] Dependency Update

## Description

Noticed a change in default close handler from 1.5.0 to 1.5.1

1.5.1 Now returns the error from `WriteControl` with `CloseMessage`
type. However this results in ErrCloseSent returned if the connection
initiated the close handshake. This is normally correct as the
connection should not be able to write after a close handshake is
initiated, except when calling the close handler. in that case nil
should be returned so that `advanceFrame()` can return the actual close
message.

## Related Tickets & Documents

## Added/updated tests?

- [x] Yes
- [ ] No, and this is why: _please replace this line with details on why
tests
      have not been included_
- [ ] I need help with writing tests

## Run verifications and test

- [ ] `make verify` is passing (fails with `GO-2023-2186 Incorrect
detection of reserved device names on Windows in path/filepath` that is
unrelated to this change)
- [x] `make test` is passing

Co-authored-by: Corey Daley <cdaley@redhat.com>
2023-11-12 19:54:23 -05:00
mstmdev 629990daa3
Use status code constant (#864)
<!--
For Work In Progress Pull Requests, please use the Draft PR feature,
see https://github.blog/2019-02-14-introducing-draft-pull-requests/ for
further details.

     For a timely review/response, please avoid force-pushing additional
     commits if your PR already received reviews or comments.

     Before submitting a Pull Request, please ensure that you have:
- 📖 Read the Contributing guide:
https://github.com/gorilla/.github/blob/main/CONTRIBUTING.md
- 📖 Read the Code of Conduct:
https://github.com/gorilla/.github/blob/main/CODE_OF_CONDUCT.md

     - Provide tests for your changes.
     - Use descriptive commit messages.
	 - Comment your code where appropriate.
	 - Squash your commits
     - Update any related documentation.

     - Add gorilla/pull-request-reviewers as a Reviewer
-->

## What type of PR is this? (check all applicable)

- [x] Refactor
- [ ] Feature
- [ ] Bug Fix
- [ ] Optimization
- [ ] Documentation Update
- [ ] Go Version Update
- [ ] Dependency Update

## Description

## Related Tickets & Documents

<!--
For pull requests that relate or close an issue, please include them
below. We like to follow [Github's guidance on linking issues to pull
requests](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue).

For example having the text: "closes #1234" would connect the current
pull
request to issue 1234.  And when we merge the pull request, Github will
automatically close the issue.
-->

- Related Issue #
- Closes #

## Added/updated tests?

- [ ] Yes
- [x] No
- [ ] I need help with writing tests

## Run verifications and test

- [ ] `make verify` is passing
- [ ] `make test` is passing
2023-11-09 06:42:05 -05:00
mstmdev b6a0d77c05
Update README.md, replace master to main (#862)
<!--
For Work In Progress Pull Requests, please use the Draft PR feature,
see https://github.blog/2019-02-14-introducing-draft-pull-requests/ for
further details.

     For a timely review/response, please avoid force-pushing additional
     commits if your PR already received reviews or comments.

     Before submitting a Pull Request, please ensure that you have:
- 📖 Read the Contributing guide:
https://github.com/gorilla/.github/blob/main/CONTRIBUTING.md
- 📖 Read the Code of Conduct:
https://github.com/gorilla/.github/blob/main/CODE_OF_CONDUCT.md

     - Provide tests for your changes.
     - Use descriptive commit messages.
	 - Comment your code where appropriate.
	 - Squash your commits
     - Update any related documentation.

     - Add gorilla/pull-request-reviewers as a Reviewer
-->

## What type of PR is this? (check all applicable)

- [ ] Refactor
- [ ] Feature
- [ ] Bug Fix
- [ ] Optimization
- [x] Documentation Update
- [ ] Go Version Update
- [ ] Dependency Update

## Description

## Related Tickets & Documents

<!--
For pull requests that relate or close an issue, please include them
below. We like to follow [Github's guidance on linking issues to pull
requests](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue).

For example having the text: "closes #1234" would connect the current
pull
request to issue 1234.  And when we merge the pull request, Github will
automatically close the issue.
-->

- Related Issue #
- Closes #

## Added/updated tests?

- [ ] Yes
- [x] No
- [ ] I need help with writing tests

## Run verifications and test

- [ ] `make verify` is passing
- [ ] `make test` is passing
2023-11-08 13:57:41 -05:00
Konstantin Burkalev aa976062fe
Fixes subprotocol selection (aling with rfc6455) (#823)
Fixes #822

**Summary of Changes**

1. Changed the order of subprotocol selection to prefer client one

---------

Co-authored-by: Corey Daley <cdaley@redhat.com>
2023-11-07 08:35:30 -05:00
Corey Daley ac0789be11
update GitHub workflows (#857)
<!--
For Work In Progress Pull Requests, please use the Draft PR feature,
see https://github.blog/2019-02-14-introducing-draft-pull-requests/ for
further details.

     For a timely review/response, please avoid force-pushing additional
     commits if your PR already received reviews or comments.

     Before submitting a Pull Request, please ensure that you have:
- 📖 Read the Contributing guide:
https://github.com/gorilla/.github/blob/main/CONTRIBUTING.md
- 📖 Read the Code of Conduct:
https://github.com/gorilla/.github/blob/main/CODE_OF_CONDUCT.md

     - Provide tests for your changes.
     - Use descriptive commit messages.
	 - Comment your code where appropriate.
	 - Squash your commits
     - Update any related documentation.

     - Add gorilla/pull-request-reviewers as a Reviewer
-->

## What type of PR is this? (check all applicable)

- [x] Refactor
- [ ] Feature
- [ ] Bug Fix
- [ ] Optimization
- [ ] Documentation Update
- [ ] Go Version Update
- [ ] Dependency Update

## Description

## Related Tickets & Documents

<!--
For pull requests that relate or close an issue, please include them
below. We like to follow [Github's guidance on linking issues to pull
requests](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue).

For example having the text: "closes #1234" would connect the current
pull
request to issue 1234.  And when we merge the pull request, Github will
automatically close the issue.
-->

- Related Issue #
- Closes #

## Added/updated tests?

- [ ] Yes
- [ ] No, and this is why: _please replace this line with details on why
tests
      have not been included_
- [ ] I need help with writing tests

## Run verifications and test

- [x] `make verify` is passing
- [x] `make test` is passing
2023-10-18 17:57:41 +05:30
Corey Daley 78c34874c8
update golang.org/x/net (#856)
<!--
For Work In Progress Pull Requests, please use the Draft PR feature,
see https://github.blog/2019-02-14-introducing-draft-pull-requests/ for
further details.

     For a timely review/response, please avoid force-pushing additional
     commits if your PR already received reviews or comments.

     Before submitting a Pull Request, please ensure that you have:
- 📖 Read the Contributing guide:
https://github.com/gorilla/.github/blob/main/CONTRIBUTING.md
- 📖 Read the Code of Conduct:
https://github.com/gorilla/.github/blob/main/CODE_OF_CONDUCT.md

     - Provide tests for your changes.
     - Use descriptive commit messages.
	 - Comment your code where appropriate.
	 - Squash your commits
     - Update any related documentation.

     - Add gorilla/pull-request-reviewers as a Reviewer
-->

## What type of PR is this? (check all applicable)

- [ ] Refactor
- [ ] Feature
- [ ] Bug Fix
- [ ] Optimization
- [ ] Documentation Update
- [ ] Go Version Update
- [x] Dependency Update

## Description

## Related Tickets & Documents

<!--
For pull requests that relate or close an issue, please include them
below. We like to follow [Github's guidance on linking issues to pull
requests](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue).

For example having the text: "closes #1234" would connect the current
pull
request to issue 1234.  And when we merge the pull request, Github will
automatically close the issue.
-->

- Related Issue #
- Closes #

## Added/updated tests?

- [ ] Yes
- [ ] No, and this is why: _please replace this line with details on why
tests
      have not been included_
- [ ] I need help with writing tests

## Run verifications and test

- [ ] `make verify` is passing
- [ ] `make test` is passing
2023-10-17 19:57:41 -04:00
Corey Daley 666c197fc9
Update go version & add verification/testing tools (#840)
Fixes #

**Summary of Changes**

1.
2. 
3.

> PS: Make sure your PR includes/updates tests! If you need help with
this part, just ask!
2023-08-27 01:31:45 +05:30
LiuYang 80393295c1
Correct way to save memory using write buffer pool and freeing net.http default buffers (#761)
**Summary of Changes**

1. Add an example that uses the write buffer pool

The loop process of the websocket connection is inner the http handler
at existing examples, This usage will cause the 8k buffer(4k read buffer
+ 4k write buffer) allocated by net.http can't be GC(Observed by heap
profiling, see picture below) . The purpose of saving memory is not
achieved even if the WriteBufferPool is used.

In example bufferpool, server process websocket connection in a new
goroutine, and the goroutine created by the net.http will exit, then the
8k buffer will be GC.


![heap](https://user-images.githubusercontent.com/12793501/148676918-872d1a6d-ce10-4146-ba01-7de114db09f5.png)

Co-authored-by: hakunaliu <hakunaliu@tencent.com>
Co-authored-by: Corey Daley <cdaley@redhat.com>
2023-08-17 11:25:09 -04:00
Corey Daley 8983b96324
Merge pull request #839 from gorilla/coreydaley-patch-1
Update README.md
2023-07-15 16:04:06 -04:00
Corey Daley 931041c5ee
Update README.md
Signed-off-by: Corey Daley <cdaley@redhat.com>
2023-07-15 10:54:14 -04:00
Matt Silverlock 76ecc29eff
archive mode 2022-12-09 11:03:16 -05:00
Ye Sijun af47554f34 check error before GotConn for trace
Signed-off-by: Ye Sijun <junnplus@gmail.com>
2022-07-12 08:37:30 -07:00
Chan Kang bc7ce893c3
Check for and report bad protocol in TLSClientConfig.NextProtos (#788)
* return an error when Dialer.TLSClientConfig.NextProtos contains a protocol that is not http/1.1

* include the likely cause of the error in the error message

* check for nil-ness of Dialer.TLSClientConfig before attempting to run the check

* addressing the review

* move the NextProtos test into a separate file so that it can be run conditionally on go versions >= 1.14

* moving the new error check into existing http response error block to reduce the possibility of false positives

* wrapping the error in %w

* using %v instead of %w for compatibility with older versions of go

* Revert "using %v instead of %w for compatibility with older versions of go"

This reverts commit d34dd940ee.

* move the unit test back into the existing test code since golang build constraint is no longer necessary

Co-authored-by: Chan Kang <chankang@chankang17@gmail.com>
2022-06-21 10:54:14 -07:00
Chan Kang 27d91a9be5 drop the versions of go that are no longer supported + add 1.18 to ci 2022-06-20 16:42:42 -07:00
JWSong 78cf1bc733
Changed the method name UnderlyingConn to NetConn to align the methods names with Go 1.18 standard library (#773) 2022-04-17 06:01:17 -07:00
Yuki Hirasawa 69d0eb9187
Add check for Sec-WebSocket-Key header (#752)
* add Sec-WebSocket-Key header verification

* add testcase to Sec-WebSocket-Key header verification
2022-02-15 17:15:20 -08:00
Lluis Campos 9111bb834a
Dialer: add optional method NetDialTLSContext (#746)
Fixes issue: https://github.com/gorilla/websocket/issues/745

With the previous interface, NetDial and NetDialContext were used for
both TLS and non-TLS TCP connections, and afterwards TLSClientConfig was
used to do the TLS handshake.

While this API works for most cases, it prevents from using more advance
authentication methods during the TLS handshake, as this is out of the
control of the user.

This commits introduces another a new dial method, NetDialTLSContext,
which is used when dialing for TLS/TCP. The code then assumes that the
handshake is done there and TLSClientConfig is not used.

This API change is fully backwards compatible and it better aligns with
net/http.Transport API, which has these two dial flavors. See:
https://pkg.go.dev/net/http#Transport

Signed-off-by: Lluis Campos <lluis.campos@northern.tech>
2022-01-03 17:59:52 -08:00
Gary Burd 2f25f7843d
Update README (#757)
- Note that a new maintainer is needed.
- Remove comparison with x/net/websocket. There's no need to describe
  the issues with that package now that the package's documentation
  points people here and elsewhere.
2022-01-03 17:49:10 -08:00
Gary Burd 4fad403619
Remove support for Go 1.8 2022-01-02 15:53:55 -08:00
Gary Burd f0643a3a18
Improve protocol error messages
To aid protocol error debugging, report all errors found in the first two bytes of a message header.
2022-01-02 12:16:08 -08:00
Gary Burd 2d6ee4c55c
Update autobahn example
- Update instructions to use docker.
- Cleanup config file.
2022-01-02 11:21:21 -08:00
Alexander Emelin beca1d3940
Fix broadcast benchmarks (#542)
* do not use cached PreparedMessage in broadcast benchmarks

* pick better name for benchmark method
2022-01-02 07:35:34 -08:00
Gary Burd bcef8431c9
Use context.Context in TLS handshake (#751)
Continued work on #730.
2022-01-01 08:43:22 -08:00
Rn 2c89656910
Modify http Method String Literal to Variable (#728) 2021-12-19 11:21:45 -05:00
Gary Burd 1905f7e442
Update source to match output from gofmt 1.17 2021-12-17 22:48:51 -05:00
Gary Burd b4b5d887ad
Document the allowed concurrency on Upgrader and Dialer (#636)
* Document allowed concurrency on Dialer.
* Document allowed concurrency on Upgrader.
2021-12-16 11:07:50 -08:00
hellflame e8629af678
improve echo example (#671) 2021-04-24 09:20:22 -07:00
Matt Silverlock c3dd95aea9
build: use build matrix; drop Go <= 1.10 (#629) 2020-09-12 12:32:13 -07:00
Matt Silverlock 78ab81e242
docs: clarify that sub protocols are not set via responseHeader arg. 2020-08-22 14:03:32 -07:00
Ran Benita 873e67e4d5
Fix how the client checks for presence of Upgrade: websocket, Connection: upgrade (#604)
The values of the `Upgrade` and `Connection` response headers can
contain multiple tokens, for example

    Connection: upgrade, keep-alive

The WebSocket RFC describes the checking of these as follows:

   2.  If the response lacks an |Upgrade| header field or the |Upgrade|
       header field contains a value that is not an ASCII case-
       insensitive match for the value "websocket", the client MUST
       _Fail the WebSocket Connection_.

   3.  If the response lacks a |Connection| header field or the
       |Connection| header field doesn't contain a token that is an
       ASCII case-insensitive match for the value "Upgrade", the client
       MUST _Fail the WebSocket Connection_.

It is careful to note "contains a value", "contains a token".

Previously, the client would reject with "bad handshake" if the header
doesn't contain exactly the value it looks for.

Change the checks to use `tokenListContainsValue` instead, which is
incidentally what the server is already doing for similar checks.
2020-08-20 06:43:18 -07:00
Matt Silverlock b65e62901f
build: clean up go.sum (#584) 2020-03-19 10:50:51 -07:00
Jon Gillham 8c288dca3e
docs: Fix typo. (#568) 2020-03-19 10:45:00 -07:00
Maxim Fominykh d11356942f
Duration order consistency when multiplying number by time unit (#570) 2020-03-19 07:01:23 -07:00
Sry Back I 81cef7da56
echo example: handle received messages as text, not HTML (#563) 2020-03-19 06:53:02 -07:00