The purpose of this change is to set this behavior in stone, so that, for example, introducing "follow redirects" by default would be a breaking change.
The [WebSocket spec](https://www.rfc-editor.org/rfc/rfc6455) actually allows the client to follow redirects:
> the server might redirect the client using a 3xx status code (but clients are not required to follow them)
I think this library should be explicit about whether it does this.
I feel like the existing "...so that callers can handle redirects, authentication, etcetera" is not worded strongly enough.
Signed-off-by: WofWca <wofwca@protonmail.com>
A zero value for the Conn.WriteControl deadline specifies no timeout,
but the feature was implemented as a very long timeout (1000 hours).
This PR updates the code to use no timeout when the deadline is zero.
See the discussion in #895 for more details.
The package ignored errors from net.Conn Set*Deadline in a few places.
Update the package to return these errors to the caller.
Ignore all other errors reported by errcheck. These errors are safe to
ignore because
- The function is making a best effort to cleanup while handling another
error.
- The function call is guaranteed to succeed.
- The error is ignored in a test.
See https://go.dev/issue/45729.
- Remove hideTempError
The hideTempError function was used to prevent connection methods from
returning a net.Error with Temporary() == true.
Connection methods do not support retry after returning any net.Error,
including errors with Temporary() == true.
Presumably hideTempError was used to prevent applications from
futilely retrying connection method calls on temporary errors.
The hideTempError function is not needed now that net.Error
Temporary() is deprecated.
- Remove use of the deprecated net.Error Temporary() method in the
default ping handler by ignoring all errors returned from
WriteControl. Ignoring errors allows the application to continue
reading messages after a write error and is consistent with how the
default close handler calls WriteControl.
The doHandshake function was split off to separate files to support
different implementations for Go < 1.16 and Go >= 1.17.
The separate files are not needed now that Go 1.20 is the minimum
supported version of Go for the project.
Use Reader.Size() (add in Go 1.10) to get the bufio.Reader's size
instead of examining the return value from Reader.Peek.
Use Writer.AvailableBuffer() (added in Go 1.18) to get the
bufio.Writer's buffer instead of observing the buffer in the underlying
writer.
Allow client to send data before the handshake is complete. Previously,
Upgrader.Upgrade rudely closed the connection.
Import golang.org/x/net/proxy instead of using the bundle in
x_net_proxy.go. There's no need to avoid the dependency on
golang.org/x/net/proxy now that Go's module system is in widespread use.
Change Dialer.DialContext to pass contexts as an argument to the dial
function instead of tunneling the context through closures. Tunneling is
no longer needed because the proxy package supports contexts. The
version of the proxy package in the bundle predates contexts!
Simplify the code for calculating the base dial function.
Prevent the HTTP proxy dialer from leaking out of the websocket package
by selecting the HTTP proxy dialer directly in the websocket package.
Previously, the HTTP dialer was registered with the proxy package.
Tests must not call *testing.T methods after the test function returns.
Use a sync.WaitGroup to ensure that server handler functions complete
before tests return.
Maintainers accidentally changed the reference commit
for v1.5.2. This change retracts v1.5.2 which also
includes a number of avoidable issues.
Fixes#927
A zero value for the Conn.WriteControl deadline specifies no timeout,
but the feature was implemented as a very long timeout (1000 hours).
This PR updates the code to use no timeout when the deadline is zero.
See the discussion in #895 for more details.
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.
### 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>
<!--
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>