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

fix: websocket conns do not require Connection: upgrade header #161

Merged
merged 1 commit into from
Dec 13, 2023

Conversation

mccutchen
Copy link
Owner

It turns out that the WebSocket API provided by browsers does not actually send the Connection: upgrade header that our websocket implementation (wrongly?) requires, so here we're dropping that requirement.

Tested with both https://websocketking.com/ and by pasting this ChatGPT-generated code into the Firefox web inspector's console:

// Open a WebSocket connection
const socket = new WebSocket('ws://localhost:8080/websocket/echo');

// Event handler for when the connection is established
socket.addEventListener('open', (event) => {
  console.log('WebSocket connection opened:', event);

  // Send test messages
  const testMessages = ['Hello, server!', 'How are you?', 'Testing WebSocket'];
  testMessages.forEach((message, index) => {
    setTimeout(() => {
      console.log('Sending message:', message);
      socket.send(message);
    }, index * 1000); // Delay messages by 1 second intervals
  });
});

// Event handler for receiving messages
socket.addEventListener('message', (event) => {
  console.log('Received message:', event.data);
});

// Event handler for errors
socket.addEventListener('error', (event) => {
  console.error('WebSocket error:', event);
});

// Event handler for when the connection is closed
socket.addEventListener('close', (event) => {
  console.log('WebSocket connection closed:', event);
});

Copy link

codecov bot commented Dec 13, 2023

Codecov Report

Merging #161 (4cbb52f) into main (21c68b8) will decrease coverage by 0.01%.
The diff coverage is n/a.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #161      +/-   ##
==========================================
- Coverage   95.05%   95.04%   -0.01%     
==========================================
  Files           9        9              
  Lines        2122     2119       -3     
==========================================
- Hits         2017     2014       -3     
  Misses         71       71              
  Partials       34       34              
Files Coverage Δ
httpbin/websocket/websocket.go 77.28% <ø> (-0.23%) ⬇️

@mccutchen mccutchen merged commit 1a41486 into main Dec 13, 2023
8 checks passed
@mccutchen mccutchen deleted the ws-connection-header branch December 13, 2023 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant