Skip to content

Commit 1c43426

Browse files
committed
Improve docs around new upgrade callback
1 parent 7468355 commit 1c43426

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

doc/api/http.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,8 +1688,11 @@ changes:
16881688
* `head` {Buffer} The first packet of the upgraded stream (may be empty)
16891689

16901690
Emitted each time a client's HTTP upgrade request is accepted. By default
1691-
all HTTP upgrade requests are ignored unless you listen to this event, in which
1692-
case they are all accepted. You can control this more precisely by using the
1691+
all HTTP upgrade requests are ignored (i.e. only regular `'request'` events
1692+
are emitted, sticking with the normal HTTP request/response flow) unless you
1693+
listen to this event, in which case they are all accepted (i.e. the `'upgrade'`
1694+
event is emitted instead, and future communication must handled directly
1695+
through the raw socket). You can control this more precisely by using the
16931696
server `shouldUpgradeCallback` option.
16941697

16951698
Listening to this event is optional and clients cannot insist on a protocol
@@ -1700,7 +1703,8 @@ event listener, meaning it will need to be bound in order to handle data
17001703
sent to the server on that socket.
17011704

17021705
If an upgrade is accepted by `shouldUpgradeCallback` but no event handler
1703-
is registered, the socket is destroyed.
1706+
is registered then the socket is destroyed, resulting in an immediate
1707+
connection closure for the client.
17041708

17051709
This event is guaranteed to be passed an instance of the {net.Socket} class,
17061710
a subclass of {stream.Duplex}, unless the user specifies a socket
@@ -3642,12 +3646,13 @@ changes:
36423646
* `ServerResponse` {http.ServerResponse} Specifies the `ServerResponse` class
36433647
to be used. Useful for extending the original `ServerResponse`. **Default:**
36443648
`ServerResponse`.
3645-
* `shouldUpgradeCallback` {Function} A callback which receives an incoming
3646-
request and returns a boolean, to control which upgrade attempts should be
3647-
accepted. Accepted upgrades will fire an `'upgrade'` event (or their sockets
3648-
will be destroyed, if no listener is registered) while rejected upgrades will
3649-
fire a `'request'` event like any non-upgrade request. This options defaults
3650-
to `() => server.listenerCount('upgrade') > 0`.
3649+
* `shouldUpgradeCallback(request)` {Function} A callback which receives an
3650+
incoming request and returns a boolean, to control which upgrade attempts
3651+
should be accepted. Accepted upgrades will fire an `'upgrade'` event (or
3652+
their sockets will be destroyed, if no listener is registered) while
3653+
rejected upgrades will fire a `'request'` event like any non-upgrade
3654+
request. This options defaults to
3655+
`() => server.listenerCount('upgrade') > 0`.
36513656
* `uniqueHeaders` {Array} A list of response headers that should be sent only
36523657
once. If the header's value is an array, the items will be joined
36533658
using `; `.

0 commit comments

Comments
 (0)