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

Update server.go #853

Closed
wants to merge 1 commit into from
Closed

Conversation

samyuktha-asokan
Copy link

@samyuktha-asokan samyuktha-asokan commented Sep 28, 2023

After the connection is upgraded from the HTTP protocol to the WebSocket protocol, the network connection cannot be used for HTTP. The net/http server panics when the application attempts to write an HTTP response to a hijacked connection. You should not use netConn to write the response headers. Instead, you should use the http.ResponseWriter to write the response headers to avoid the log "http: response.WriteHeader on hijacked connection from...."

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

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update
  • Go Version Update
  • Dependency Update

Description

Related Tickets & Documents

  • 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

After the connection is upgraded from the HTTP protocol to the WebSocket protocol, the network connection cannot be used for HTTP. The net/http server panics when the application attempts to write an HTTP response to a hijacked connection. You should not use netConn to write the response headers. Instead, you should use the http.ResponseWriter to write the response headers to avoid the log "http: response.WriteHeader on hijacked connection from...."

Signed-off-by: samyuktha-asokan <[email protected]>
@ghost
Copy link

ghost commented Sep 28, 2023

This PR attempts to write the websocket handshake response headers to the connection using ResponseWriter.Write method. This fails for two reasons:

  • ResponseWriter.Write fails on a hijacked connection.
  • Even if ResponseWriter.Write did not fail on the hijacked connection, ResponseWriter.Write writes the data to the response body, not the response header.

Many tests will fail with this change.

After the connection is upgraded from the HTTP protocol to the WebSocket protocol, the network connection cannot be used for HTTP

This is not true. The hijacker takes control of the connection and can implement whatever protocol it want, including HTTP.

@ghost
Copy link

ghost commented Feb 15, 2024

@jaitaiwan This should be closed. Tests fail with the change. See previous comment.

@AlexVulaj AlexVulaj closed this Mar 6, 2024
@AlexVulaj
Copy link
Member

I've closed this PR as per the comment above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants