websockets / ws

Simple to use, blazing fast and thoroughly tested WebSocket client and server for Node.js
MIT License
21.34k stars 2.3k forks source link

Source Code Confusion #2232

Closed yuhao423 closed 3 weeks ago

yuhao423 commented 3 weeks ago

Is there an existing issue for this?

Description

Hello lpinca, this is not a bug report, I've been reading the ws source code recently and it's great, but a question that is confusing me is what are the three parameters that are returned after sending an http request to upgrade, res I understand is the upgrade field that is returned by the server, and socket and head I don't know what they are. The specific code is lib/websocket.js initAsClient function in the req.on('upgrade'),sorry to bother you.

image

ws version

No response

Node.js Version

No response

System

No response

Expected result

No response

Actual result

No response

Attachments

No response

lpinca commented 3 weeks ago

See https://nodejs.org/api/http.html#event-upgrade and https://nodejs.org/api/http.html#event-upgrade_1. The former is emitted on the client, the latter on the server. The arguments are the same.

yuhao423 commented 3 weeks ago

Thanks, I should spend more time looking at the HTTP API documentation.

lpinca commented 3 weeks ago

I'm closing this as answered.