| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -119,7 +119,7 @@ Returns a promise with the result of the `Dispatcher.request` method. | |||
| 119 | 119 | ||
| 120 | 120 | Calls `options.dispatcher.request(options)`. | |
| 121 | 121 | ||
| 122 | - See [Dispatcher.request](./docs/api/Dispatcher.md#dispatcherrequestoptions-callback) for more details. | ||
| 122 | + See [Dispatcher.request](./docs/api/Dispatcher.md#dispatcherrequestoptions-callback) for more details, and [request examples](./examples/README.md) for examples. | ||
| 123 | 123 | ||
| 124 | 124 | ### `undici.stream([url, options, ]factory): Promise` | |
| 125 | 125 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,62 @@ | |||
| 1 | + # Debug | ||
| 2 | + | ||
| 3 | + Undici (and subsenquently `fetch` and `websocket`) exposes a debug statement that can be enabled by setting `NODE_DEBUG` within the environment. | ||
| 4 | + | ||
| 5 | + The flags availabile are: | ||
| 6 | + | ||
| 7 | + ## `undici` | ||
| 8 | + | ||
| 9 | + This flag enables debug statements for the core undici library. | ||
| 10 | + | ||
| 11 | + ```sh | ||
| 12 | + NODE_DEBUG=undici node script.js | ||
| 13 | + | ||
| 14 | + UNDICI 16241: connecting to nodejs.org using https:h1 | ||
| 15 | + UNDICI 16241: connecting to nodejs.org using https:h1 | ||
| 16 | + UNDICI 16241: connected to nodejs.org using https:h1 | ||
| 17 | + UNDICI 16241: sending request to GET https://nodejs.org// | ||
| 18 | + UNDICI 16241: received response to GET https://nodejs.org// - HTTP 307 | ||
| 19 | + UNDICI 16241: connecting to nodejs.org using https:h1 | ||
| 20 | + UNDICI 16241: trailers received from GET https://nodejs.org// | ||
| 21 | + UNDICI 16241: connected to nodejs.org using https:h1 | ||
| 22 | + UNDICI 16241: sending request to GET https://nodejs.org//en | ||
| 23 | + UNDICI 16241: received response to GET https://nodejs.org//en - HTTP 200 | ||
| 24 | + UNDICI 16241: trailers received from GET https://nodejs.org//en | ||
| 25 | + ``` | ||
| 26 | + | ||
| 27 | + ## `fetch` | ||
| 28 | + | ||
| 29 | + This flag enables debug statements for the `fetch` API. | ||
| 30 | + | ||
| 31 | + > **Note**: statements are pretty similar to the ones in the `undici` flag, but scoped to `fetch` | ||
| 32 | + | ||
| 33 | + ```sh | ||
| 34 | + NODE_DEBUG=fetch node script.js | ||
| 35 | + | ||
| 36 | + FETCH 16241: connecting to nodejs.org using https:h1 | ||
| 37 | + FETCH 16241: connecting to nodejs.org using https:h1 | ||
| 38 | + FETCH 16241: connected to nodejs.org using https:h1 | ||
| 39 | + FETCH 16241: sending request to GET https://nodejs.org// | ||
| 40 | + FETCH 16241: received response to GET https://nodejs.org// - HTTP 307 | ||
| 41 | + FETCH 16241: connecting to nodejs.org using https:h1 | ||
| 42 | + FETCH 16241: trailers received from GET https://nodejs.org// | ||
| 43 | + FETCH 16241: connected to nodejs.org using https:h1 | ||
| 44 | + FETCH 16241: sending request to GET https://nodejs.org//en | ||
| 45 | + FETCH 16241: received response to GET https://nodejs.org//en - HTTP 200 | ||
| 46 | + FETCH 16241: trailers received from GET https://nodejs.org//en | ||
| 47 | + ``` | ||
| 48 | + | ||
| 49 | + ## `websocket` | ||
| 50 | + | ||
| 51 | + This flag enables debug statements for the `Websocket` API. | ||
| 52 | + | ||
| 53 | + > **Note**: statements can overlap with `UNDICI` ones if `undici` or `fetch` flag has been enabled as well. | ||
| 54 | + | ||
| 55 | + ```sh | ||
| 56 | + NODE_DEBUG=fetch node script.js | ||
| 57 | + | ||
| 58 | + WEBSOCKET 18309: connecting to echo.websocket.org using https:h1 | ||
| 59 | + WEBSOCKET 18309: connected to echo.websocket.org using https:h1 | ||
| 60 | + WEBSOCKET 18309: sending request to GET https://echo.websocket.org// | ||
| 61 | + WEBSOCKET 18309: connection opened <ip_address> | ||
| 62 | + ``` | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -105,7 +105,7 @@ You can not assume that this event is related to any specific request. | |||
| 105 | 105 | import diagnosticsChannel from 'diagnostics_channel' | |
| 106 | 106 | ||
| 107 | 107 | diagnosticsChannel.channel('undici:client:beforeConnect').subscribe(({ connectParams, connector }) => { | |
| 108 | - // const { host, hostname, protocol, port, servername } = connectParams | ||
| 108 | + // const { host, hostname, protocol, port, servername, version } = connectParams | ||
| 109 | 109 | // connector is a function that creates the socket | |
| 110 | 110 | }) | |
| 111 | 111 | ``` | |
@@ -118,7 +118,7 @@ This message is published after a connection is established. | |||
| 118 | 118 | import diagnosticsChannel from 'diagnostics_channel' | |
| 119 | 119 | ||
| 120 | 120 | diagnosticsChannel.channel('undici:client:connected').subscribe(({ socket, connectParams, connector }) => { | |
| 121 | - // const { host, hostname, protocol, port, servername } = connectParams | ||
| 121 | + // const { host, hostname, protocol, port, servername, version } = connectParams | ||
| 122 | 122 | // connector is a function that creates the socket | |
| 123 | 123 | }) | |
| 124 | 124 | ``` | |
@@ -131,7 +131,7 @@ This message is published if it did not succeed to create new connection | |||
| 131 | 131 | import diagnosticsChannel from 'diagnostics_channel' | |
| 132 | 132 | ||
| 133 | 133 | diagnosticsChannel.channel('undici:client:connectError').subscribe(({ error, socket, connectParams, connector }) => { | |
| 134 | - // const { host, hostname, protocol, port, servername } = connectParams | ||
| 134 | + // const { host, hostname, protocol, port, servername, version } = connectParams | ||
| 135 | 135 | // connector is a function that creates the socket | |
| 136 | 136 | console.log(`Connect failed with ${error.message}`) | |
| 137 | 137 | }) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,9 @@ const fetchImpl = require('./lib/fetch').fetch | |||
| 4 | 4 | ||
| 5 | 5 | module.exports.fetch = function fetch (resource, init = undefined) { | |
| 6 | 6 | return fetchImpl(resource, init).catch((err) => { | |
| 7 | - Error.captureStackTrace(err, this) | ||
| 7 | + if (typeof err === 'object') { | ||
| 8 | + Error.captureStackTrace(err, this) | ||
| 9 | + } | ||
| 8 | 10 | throw err | |
| 9 | 11 | }) | |
| 10 | 12 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,9 +6,9 @@ const kSignal = Symbol('kSignal') | |||
| 6 | 6 | ||
| 7 | 7 | function abort (self) { | |
| 8 | 8 | if (self.abort) { | |
| 9 | - self.abort() | ||
| 9 | + self.abort(self[kSignal]?.reason) | ||
| 10 | 10 | } else { | |
| 11 | - self.onError(new RequestAbortedError()) | ||
| 11 | + self.onError(self[kSignal]?.reason ?? new RequestAbortedError()) | ||
| 12 | 12 | } | |
| 13 | 13 | } | |
| 14 | 14 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -112,14 +112,12 @@ class Cache { | |||
| 112 | 112 | // 5.5.2 | |
| 113 | 113 | for (const response of responses) { | |
| 114 | 114 | // 5.5.2.1 | |
| 115 | - const responseObject = new Response(response.body?.source ?? null) | ||
| 116 | - const body = responseObject[kState].body | ||
| 115 | + const responseObject = new Response(null) | ||
| 117 | 116 | responseObject[kState] = response | |
| 118 | - responseObject[kState].body = body | ||
| 119 | 117 | responseObject[kHeaders][kHeadersList] = response.headersList | |
| 120 | 118 | responseObject[kHeaders][kGuard] = 'immutable' | |
| 121 | 119 | ||
| 122 | - responseList.push(responseObject) | ||
| 120 | + responseList.push(responseObject.clone()) | ||
| 123 | 121 | } | |
| 124 | 122 | ||
| 125 | 123 | // 6. | |
@@ -146,16 +144,24 @@ class Cache { | |||
| 146 | 144 | webidl.brandCheck(this, Cache) | |
| 147 | 145 | webidl.argumentLengthCheck(arguments, 1, { header: 'Cache.addAll' }) | |
| 148 | 146 | ||
| 149 | - requests = webidl.converters['sequence<RequestInfo>'](requests) | ||
| 150 | - | ||
| 151 | 147 | // 1. | |
| 152 | 148 | const responsePromises = [] | |
| 153 | 149 | ||
| 154 | 150 | // 2. | |
| 155 | 151 | const requestList = [] | |
| 156 | 152 | ||
| 157 | 153 | // 3. | |
| 158 | - for (const request of requests) { | ||
| 154 | + for (let request of requests) { | ||
| 155 | + if (request === undefined) { | ||
| 156 | + throw webidl.errors.conversionFailed({ | ||
| 157 | + prefix: 'Cache.addAll', | ||
| 158 | + argument: 'Argument 1', | ||
| 159 | + types: ['undefined is not allowed'] | ||
| 160 | + }) | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + request = webidl.converters.RequestInfo(request) | ||
| 164 | + | ||
| 159 | 165 | if (typeof request === 'string') { | |
| 160 | 166 | continue | |
| 161 | 167 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,7 @@ const net = require('net') | |||
| 9 | 9 | const http = require('http') | |
| 10 | 10 | const { pipeline } = require('stream') | |
| 11 | 11 | const util = require('./core/util') | |
| 12 | + const { channels } = require('./core/diagnostics') | ||
| 12 | 13 | const timers = require('./timers') | |
| 13 | 14 | const Request = require('./core/request') | |
| 14 | 15 | const DispatcherBase = require('./dispatcher-base') | |
@@ -108,21 +109,6 @@ const FastBuffer = Buffer[Symbol.species] | |||
| 108 | 109 | ||
| 109 | 110 | const kClosedResolve = Symbol('kClosedResolve') | |
| 110 | 111 | ||
| 111 | - const channels = {} | ||
| 112 | - | ||
| 113 | - try { | ||
| 114 | - const diagnosticsChannel = require('diagnostics_channel') | ||
| 115 | - channels.sendHeaders = diagnosticsChannel.channel('undici:client:sendHeaders') | ||
| 116 | - channels.beforeConnect = diagnosticsChannel.channel('undici:client:beforeConnect') | ||
| 117 | - channels.connectError = diagnosticsChannel.channel('undici:client:connectError') | ||
| 118 | - channels.connected = diagnosticsChannel.channel('undici:client:connected') | ||
| 119 | - } catch { | ||
| 120 | - channels.sendHeaders = { hasSubscribers: false } | ||
| 121 | - channels.beforeConnect = { hasSubscribers: false } | ||
| 122 | - channels.connectError = { hasSubscribers: false } | ||
| 123 | - channels.connected = { hasSubscribers: false } | ||
| 124 | - } | ||
| 125 | - | ||
| 126 | 112 | /** | |
| 127 | 113 | * @type {import('../types/client').default} | |
| 128 | 114 | */ | |
@@ -1191,6 +1177,7 @@ async function connect (client) { | |||
| 1191 | 1177 | hostname, | |
| 1192 | 1178 | protocol, | |
| 1193 | 1179 | port, | |
| 1180 | + version: client[kHTTPConnVersion], | ||
| 1194 | 1181 | servername: client[kServerName], | |
| 1195 | 1182 | localAddress: client[kLocalAddress] | |
| 1196 | 1183 | }, | |
@@ -1284,6 +1271,7 @@ async function connect (client) { | |||
| 1284 | 1271 | hostname, | |
| 1285 | 1272 | protocol, | |
| 1286 | 1273 | port, | |
| 1274 | + version: client[kHTTPConnVersion], | ||
| 1287 | 1275 | servername: client[kServerName], | |
| 1288 | 1276 | localAddress: client[kLocalAddress] | |
| 1289 | 1277 | }, | |
@@ -1306,6 +1294,7 @@ async function connect (client) { | |||
| 1306 | 1294 | hostname, | |
| 1307 | 1295 | protocol, | |
| 1308 | 1296 | port, | |
| 1297 | + version: client[kHTTPConnVersion], | ||
| 1309 | 1298 | servername: client[kServerName], | |
| 1310 | 1299 | localAddress: client[kLocalAddress] | |
| 1311 | 1300 | }, | |
@@ -1658,19 +1647,6 @@ function writeH2 (client, session, request) { | |||
| 1658 | 1647 | return false | |
| 1659 | 1648 | } | |
| 1660 | 1649 | ||
| 1661 | - try { | ||
| 1662 | - // TODO(HTTP/2): Should we call onConnect immediately or on stream ready event? | ||
| 1663 | - request.onConnect((err) => { | ||
| 1664 | - if (request.aborted || request.completed) { | ||
| 1665 | - return | ||
| 1666 | - } | ||
| 1667 | - | ||
| 1668 | - errorRequest(client, request, err || new RequestAbortedError()) | ||
| 1669 | - }) | ||
| 1670 | - } catch (err) { | ||
| 1671 | - errorRequest(client, request, err) | ||
| 1672 | - } | ||
| 1673 | - | ||
| 1674 | 1650 | if (request.aborted) { | |
| 1675 | 1651 | return false | |
| 1676 | 1652 | } | |
@@ -1682,9 +1658,34 @@ function writeH2 (client, session, request) { | |||
| 1682 | 1658 | headers[HTTP2_HEADER_AUTHORITY] = host || client[kHost] | |
| 1683 | 1659 | headers[HTTP2_HEADER_METHOD] = method | |
| 1684 | 1660 | ||
| 1661 | + try { | ||
| 1662 | + // We are already connected, streams are pending. | ||
| 1663 | + // We can call on connect, and wait for abort | ||
| 1664 | + request.onConnect((err) => { | ||
| 1665 | + if (request.aborted || request.completed) { | ||
| 1666 | + return | ||
| 1667 | + } | ||
| 1668 | + | ||
| 1669 | + err = err || new RequestAbortedError() | ||
| 1670 | + | ||
| 1671 | + if (stream != null) { | ||
| 1672 | + util.destroy(stream, err) | ||
| 1673 | + | ||
| 1674 | + h2State.openStreams -= 1 | ||
| 1675 | + if (h2State.openStreams === 0) { | ||
| 1676 | + session.unref() | ||
| 1677 | + } | ||
| 1678 | + } | ||
| 1679 | + | ||
| 1680 | + errorRequest(client, request, err) | ||
| 1681 | + }) | ||
| 1682 | + } catch (err) { | ||
| 1683 | + errorRequest(client, request, err) | ||
| 1684 | + } | ||
| 1685 | + | ||
| 1685 | 1686 | if (method === 'CONNECT') { | |
| 1686 | 1687 | session.ref() | |
| 1687 | - // we are already connected, streams are pending, first request | ||
| 1688 | + // We are already connected, streams are pending, first request | ||
| 1688 | 1689 | // will create a new stream. We trigger a request to create the stream and wait until | |
| 1689 | 1690 | // `ready` event is triggered | |
| 1690 | 1691 | // We disabled endStream to allow the user to write to the stream | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,6 +28,8 @@ class CompatFinalizer { | |||
| 28 | 28 | }) | |
| 29 | 29 | } | |
| 30 | 30 | } | |
| 31 | + | ||
| 32 | + unregister (key) {} | ||
| 31 | 33 | } | |
| 32 | 34 | ||
| 33 | 35 | module.exports = function () { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments