James Coglan
d892d3bad5
Emit ping and pong events from the Server driver
2020-02-14 14:42:15 +01:00
Erick Aguiar
43656559b0
handling match in empty string
...
The previous fix (#26 ) wasn't handling the return of the match function,
witch is null when the string is empty.
2020-02-14 14:37:47 +01:00
James Coglan
998a1725ea
Formatting change: {...} should have spaces inside the braces
2019-06-11 15:56:58 +01:00
James Coglan
efb46fb455
Merge remote-tracking branch 'funtaps/regex_fix'
2019-05-29 00:07:17 +01:00
James Coglan
5723676b7b
Make the HTTP parser load correctly if process.version is not set, and remove some code that's supporting Node from before v0.6.
2019-05-24 17:45:47 +01:00
James Coglan
f27aa59fd8
Use Buffer.write() instead of Buffer.copy() to write strings into buffers.
2019-05-24 17:22:51 +01:00
Luigi Pinca
1682df15bf
Avoid using deprecated Buffer API
...
Usage of `Buffer` constructor has been deprecated due to usability
issues that can potentially lead to accidental security issues.
Refs: https://nodejs.org/api/deprecations.html#deprecations_dep0005_buffer_constructor
Tracking: https://github.com/nodejs/node/issues/19079
2018-03-22 09:49:28 +01:00
Funtov Kirill
0f1ae9c9ae
Regex empty match fix
2018-01-23 11:49:53 +03:00
James Coglan
47c5e4d9ee
Handle errors in the draft76 handshake by throwing an error that Base.start() will catch, triggering a 400 response.
2017-11-23 08:51:35 +00:00
James Coglan
ae30f9952f
Bake the isWebSocket() check into the start() method so that if somebody constructs a driver without making that check, the driver will send a 400 response.
2017-11-23 08:30:24 +00:00
James Coglan
e260d4d788
If the request headers contain any of the necessary values for Hybi, then use it. i.e. if Sec-WebSocket-Key is present but not Sec-WebSocket-Version, we should still interpret it as a Hybi connection.
2017-11-19 20:03:38 +00:00
James Coglan
287bbe8a7a
If any driver fails to generate a handshake response, then send a 400. This means the initial http() method to select a driver doesn't need to contain all the validation logic for all the details of each protocol version, but protocol errors still result in a failed connection.
2017-11-19 19:47:30 +00:00
James Coglan
cad92a6e4e
Remove redundant request method check from isWebSocket().
2017-11-19 19:40:22 +00:00
James Coglan
1325828a9e
Add ping/pong events to the API.
2017-08-02 21:57:47 +01:00
James Coglan
751c77aa1d
Replace the built-in Node HTTP parser with the http-parser-js package.
2017-07-30 19:34:41 +01:00
James Coglan
b76f4e27d0
Correct the HTTP parser magic numbers. The numbers we had were correct for Node 0.12 but not for releases since then.
2017-07-30 19:26:45 +01:00
James Coglan
6a92cacf62
Apply masking to messages once the payload has been placed in the frame buffer rather than mutating the original message.
2016-04-27 22:28:58 +01:00
James Coglan
7f3bb13b5c
In draft-75/76, convert all non-string values to strings before sending.
2016-01-06 23:20:47 +00:00
James Coglan
ffa0aa3a8f
Convert numbers to strings when sending frames.
...
In draft-75/76, passing a number to text() or frame() results in the
sender allocating a buffer of that size and sending it to the other
peer, leaking random blocks of memory.
In hybi, a call to text(), binary() or ping() with a number will fail,
because the input is expected to be a buffer and so an internal method
call fails.
Both kinds of driver now convert numbers to strings, which is what
browsers do with calls to send().
2016-01-06 23:12:44 +00:00
James Coglan
b0b0d69ce4
Throw a more helpful error if a client driver is created with an invalid URL.
2015-10-17 21:44:36 +01:00
James Coglan
5b59d0fcd8
Use the modulo operator rather than Math.floor() to check whether the draft-76 keys are legit.
2015-10-02 21:35:22 +01:00
James Coglan
68990a260b
Close the connection if a draft-76 client sends a Sec-WebSocket-Key header where the numeric value is a non-integer multiple of the number of spaces.
2015-10-01 23:47:15 +01:00
James Coglan
89e2a7da82
Emit a protocol error when a closing frame has a 1-byte payload.
2015-07-17 22:05:26 +01:00
James Coglan
70ef5440c4
Emit close code 1000 if the closing frame does not contain one.
2015-07-15 18:04:02 +01:00
James Coglan
c8e5f1eb78
A few stylistic tweaks.
2015-07-11 23:26:49 +01:00
James Coglan
eb5e39e7e3
Standardise the words used to refer to chunks of parser input.
2015-07-10 22:37:54 +01:00
James Coglan
a95f68080e
Use the buffer.{read,write}UInt{16,32}BE functions to parse and write numbers rather than implementing such things ourselves.
2015-07-10 20:01:44 +01:00
James Coglan
14937dd365
Emit an error event *after* setting the ready state to 3.
2015-07-08 20:14:14 +01:00
James Coglan
780dd331fe
The 'connect' event should emit a ConnectEvent object.
2015-07-07 21:33:15 +01:00
James Coglan
4a3d51cc5b
Incorporate StreamReader into Draft75 so that it retains input and recovers safely from exceptions in event listeners.
2015-07-07 21:30:06 +01:00
James Coglan
ed17186354
In the Hybi driver, perform parser state changes before validating and emitting events. This protects the parser against errors thrown by event listeners.
2015-07-07 20:36:30 +01:00
James Coglan
1df1293456
Change stage in the Base.shutdown() method to that all parsers stop processing input.
2015-07-04 21:07:34 +01:00
James Coglan
d901d3e48d
If an event listener emits an error, close the connection with code 1011.
2015-07-04 20:54:22 +01:00
Victor Gama
5f6873ebc0
Ensure message is always defined
2015-07-04 18:33:59 +01:00
Victor Gama
309b5651a7
Implement 'pong' command to hybi.js
2015-07-04 18:33:59 +01:00
James Coglan
0034f5fe19
Fail the connection when the server receives an invalid Sec-WebSocket-Extensions header.
2015-03-26 08:51:34 +00:00
James Coglan
8a0235ef51
Don't send a close frame in response to receiving one, if we already sent a close frame.
2015-03-12 12:58:43 +00:00
James Coglan
23d0a9ea5e
Don't parse incoming data if the client is already closed. This stops the headers being interpreted as WebSocket data if the client is closed before receiving the server's handshake. Fixes https://github.com/faye/websocket-extensions-node/issues/1 .
2015-02-21 12:34:37 +00:00
James Coglan
8cf42d6050
Apply @zingaburga's StreamReader optimisations from https://github.com/faye/websocket-driver-node/issues/10 .
2015-02-16 20:07:40 +00:00
James Coglan
ebe4ce1382
Because Driver.frame() will now admit input when in readyState 2 (to allow for async extension shutdown), the Messages stream should use the text() and binary() methods that will block messages in that state.
2015-02-16 09:51:40 +00:00
James Coglan
daa37974c6
Don't emit further error/close events if the driver is already closing.
2015-02-16 09:08:10 +00:00
James Coglan
cc5e5c245e
Use Extensions.close(callback) to make sure close follows all pending messages.
...
viz.: https://github.com/faye/websocket-extensions-node/commit/1b77290e8279f654089eac963942309fb19b9312
2015-02-15 13:18:21 +00:00
James Coglan
bdc081ab57
Adapt to the changes to the HTTPParser API introduced in iojs.
2015-02-02 21:06:51 +00:00
James Coglan
5cba268409
Throw an error if drivers are created with unrecognised options.
2014-12-17 22:18:06 +00:00
James Coglan
23675e08ee
Don't expose the internal frame structure of messages to extensions; they should not be able to depend on seeing the actual frame boundaries off the wire because that requires all extensions to leave them intact.
2014-12-06 22:08:37 +00:00
James Coglan
66f46330e7
Remove some blank lines.
2014-12-05 19:36:06 +00:00
James Coglan
7376f48d6a
Catch errors raised by Extensions.activate().
2014-12-02 22:53:16 +00:00
James Coglan
330fa2073d
Don't assume that messages coming out of extensions have anything but the standard websocket-extensions API.
2014-11-29 01:54:20 +00:00
James Coglan
58474a837c
Populate the Message.data field before handing off to extensions.
2014-11-29 01:13:18 +00:00
James Coglan
82182eb348
Close the Extensions object when ending the session.
2014-11-29 00:55:02 +00:00