Tags: cnlabs-rus/nock
Tags
fix: alias connection to socket. (nock#1590) `ClientRequest.connection` is an alias for `ClientRequest.socket`. https://nodejs.org/api/http.html#http_request_socket https://github.com/nodejs/node/blob/master/lib/_http_client.js#L640-L641 `IncomingMessage.connection` is an alias for `IncomingMessage.socket`. https://github.com/nodejs/node/blob/master/lib/_http_incoming.js#L44-L45 Co-Authored-By: Paul Melnikow <[email protected]>
feat: Throw error if request headers are not an object (nock#1574) Throw if headersFieldNamesToLowerCase is not provided an object. Adds a test to cover the exception case. Going through the git history for this function, all the way back to when it was added with 4048734, I can't find a case where a non-object input was valid. Once PR # 1564 is merged in, this utility will only be called in two places: - Creating an Interceptor if the Scope was created with `options` - When http.request is called with an `options` object In both places, providing defined, but non-object values causes chaos. If the value is a truthy, non-iterable then the header was ignored during matching. For example, the following will match Interceptors as if `reqheaders` had not been provided. ```js nock('http:https://example.com', { reqheaders: 1 }).get('/').reply ``` However, if the value was provided as a non-plain object iterable, such as an array or string, the header matching logic would attempt to match header field names with numerical keys, rendering the whole Scope useless.
feat(reply): Response headers to more closely match Node's functional… …ity. (nock#1564) * Response headers to more closely match Node. Updates the header handling in the `Interceptor` and `RequestOverrider` with the intention of mimicking the native behavior of `http.IncomingMessage.rawHeaders`. > The raw request/response headers list exactly as they were received. There are three fundamental changes in this changeset: 1) Header Input Type Previously, headers could be provided to: - `Scope.defaultReplyHeaders` as a plain object - `Interceptor.reply(status, body, headers)` as a plain object or an array of raw headers - `Interceptor.reply(() => [status, body, headers]` as a plain object Now, all three allow consistent inputs where the headers can be provided as a plain object, an array of raw headers, or a `Map`. 2) Duplicate Headers Folding This change deviates from the suggested guidelines laid out in nock#1553 because those guidelines didn't properly handle duplicate headers, especially when some are defined as defaults. This change was modeled to duplicate [Node's implementation](https://github.com/nodejs/node/blob/908292cf1f551c614a733d858528ffb13fb3a524/lib/_http_incoming.js#L245) ([relevant docs](https://nodejs.org/api/http.html#http_message_headers)). It specifically lays out how duplicate headers are handled depending on the field name. In the case of default headers, they are not included on the `Response` (not even in the raw headers) if the field name exists in the reply headers (using a case-insensitive comparison). 3) Raw Headers are the Source of Truth Previously, the `Interceptor` and `RequestOverrider` mostly keep track of headers as a plain object and the array of raw headers was created by looping that object. This was the cause for inconsistencies with the final result of the raw headers. The problem with that approach is that converting raw headers to an object is a lossy process, so going backwards makes it impossible to guarantee the correct results. This change reverses that logic and now the `Interceptor` and `RequestOverrider` maintain the header data in raw arrays. All additions to headers are only added to raw headers. The plain headers object is never mutated directly, and instead is [re]created from the raw headers as needed.
feat: Throw an error on invalid truthy reply status codes (nock#1571)
fix: Update and clarify how .reply() can be invoked with functions (n… …ock#1520) Ref https://github.com/nock/nock/pull/1517/files#r280139478 Closes nock#1222
fix: `req.end(cb)` compatibility with Node 12 (nock#1551)
fix: Fix `req.end(cb)`; prevent TypeError in Node 12 (nock#1547) According to the docs, `req.end` can accept callback as a first argument. That's what `got` module does. Closes nock#1509 ``` request.end([data[, encoding]][, callback])# History data <string> | <Buffer> encoding <string> callback <Function> Returns: <this> Finishes sending the request. If any parts of the body are unsent, it will flush them to the stream. If the request is chunked, this will send the terminating '0\r\n\r\n'. If data is specified, it is equivalent to calling request.write(data, encoding) followed by request.end(callback). If callback is specified, it will be called when the request stream is finished. ```
fix: Restore behavior of Interceptor.filteringPath (nock#1543) Calling `filteringPath` on the intercept instance was broken as the transform fn set on the scope had the wrong name. Proxying to the Scope’s method allows for the regex version to work too. The bulk of the changed lines come from moving the tests to their appropriate file since the real logic acts on the Scope. Found when looking at Uncovered lines in coveralls.
PreviousNext