Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

request

Package Overview
Dependencies
Maintainers
4
Versions
126
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

request - npm Package Compare versions

Comparing version 2.80.0 to 2.81.0

3

lib/helpers.js

@@ -5,2 +5,3 @@ 'use strict'

, crypto = require('crypto')
, Buffer = require('safe-buffer').Buffer

@@ -39,3 +40,3 @@ var defer = typeof setImmediate === 'undefined'

function toBase64 (str) {
return (new Buffer(str || '', 'utf8')).toString('base64')
return Buffer.from(str || '', 'utf8').toString('base64')
}

@@ -42,0 +43,0 @@

@@ -6,2 +6,3 @@ 'use strict'

, isstream = require('isstream')
, Buffer = require('safe-buffer').Buffer

@@ -75,3 +76,3 @@

}
return chunked ? body.append(part) : body.push(new Buffer(part))
return chunked ? body.append(part) : body.push(Buffer.from(part))
}

@@ -78,0 +79,0 @@

@@ -9,2 +9,3 @@ 'use strict'

, crypto = require('crypto')
, Buffer = require('safe-buffer').Buffer

@@ -74,3 +75,3 @@

return new Buffer(sha1).toString('base64')
return Buffer.from(sha1).toString('base64')
}

@@ -77,0 +78,0 @@

@@ -10,3 +10,3 @@ {

],
"version": "2.80.0",
"version": "2.81.0",
"author": "Mikeal Rogers <mikeal.rogers@gmail.com>",

@@ -38,3 +38,3 @@ "repository": {

"form-data": "~2.1.1",
"har-validator": "~4.2.0",
"har-validator": "~4.2.1",
"hawk": "~3.1.3",

@@ -48,6 +48,7 @@ "http-signature": "~1.1.0",

"performance-now": "^0.2.0",
"qs": "~6.3.0",
"qs": "~6.4.0",
"safe-buffer": "^5.0.1",
"stringstream": "~0.0.4",
"tough-cookie": "~2.3.0",
"tunnel-agent": "~0.4.1",
"tunnel-agent": "^0.6.0",
"uuid": "^3.0.0"

@@ -54,0 +55,0 @@ },

@@ -815,13 +815,19 @@

- `time` - If `true`, the request-response cycle (including all redirects) is timed at millisecond resolution, and the result provided on the response's `elapsedTime` property. The `responseStartTime` property is also available to indicate the timestamp when the response begins. In addition, there is a `.timings` object available with the following properties:
- `start`: Timestamp when `request()` was initialized
- `socket` Timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_socket) module's `socket` event fires. This happens when the socket is assigned to the request (after DNS has been resolved).
- `connect`: Timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_connect) module's `connect` event fires. This happens when the server acknowledges the TCP connection.
- `response`: Timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_response) module's `response` event fires. This happens when the first bytes are received from the server.
- `end`: Timestamp when the last bytes of the response are received.
- `dns`: Duration of DNS lookup (`timings.socket` - `timings.start`)
- `tcp`: Duration of TCP connection (`timings.connect` - `timings.socket`)
- `firstByte`: Duration of HTTP server response (`timings.response` - `timings.connect`)
- `download`: Duration of HTTP download (`timings.end` - `timings.response`)
- `total`: Duration entire HTTP round-trip (`timings.end` - `timings.start`)
- `time` - If `true`, the request-response cycle (including all redirects) is timed at millisecond resolution. When set, the following properties are added to the response object:
- `elapsedTime` Duration of the entire request/response in milliseconds (*deprecated*).
- `responseStartTime` Timestamp when the response began (in Unix Epoch milliseconds) (*deprecated*).
- `timingStart` Timestamp of the start of the request (in Unix Epoch milliseconds).
- `timings` Contains event timestamps in millisecond resolution relative to `timingStart`. If there were redirects, the properties reflect the timings of the final request in the redirect chain:
- `socket` Relative timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_socket) module's `socket` event fires. This happens when the socket is assigned to the request.
- `lookup` Relative timestamp when the [`net`](https://nodejs.org/api/net.html#net_event_lookup) module's `lookup` event fires. This happens when the DNS has been resolved.
- `connect`: Relative timestamp when the [`net`](https://nodejs.org/api/net.html#net_event_connect) module's `connect` event fires. This happens when the server acknowledges the TCP connection.
- `response`: Relative timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_response) module's `response` event fires. This happens when the first bytes are received from the server.
- `end`: Relative timestamp when the last bytes of the response are received.
- `timingPhases` Contains the durations of each request phase. If there were redirects, the properties reflect the timings of the final request in the redirect chain:
- `wait`: Duration of socket initialization (`timings.socket`)
- `dns`: Duration of DNS lookup (`timings.lookup` - `timings.socket`)
- `tcp`: Duration of TCP connection (`timings.connect` - `timings.socket`)
- `firstByte`: Duration of HTTP server response (`timings.response` - `timings.connect`)
- `download`: Duration of HTTP download (`timings.end` - `timings.response`)
- `total`: Duration entire HTTP round-trip (`timings.end`)

@@ -828,0 +834,0 @@ - `har` - A [HAR 1.2 Request Object](http://www.softwareishard.com/blog/har-12-spec/#request), will be processed from HAR format into options overwriting matching values *(see the [HAR 1.2 section](#support-for-har-1.2) for details)*

@@ -32,2 +32,3 @@ 'use strict'

, now = require('performance-now')
, Buffer = require('safe-buffer').Buffer

@@ -421,3 +422,3 @@ var safeStringify = helpers.safeStringify

if (isTypedArray(self.body)) {
self.body = new Buffer(self.body)
self.body = Buffer.from(self.body)
}

@@ -719,3 +720,9 @@

if (self.timing) {
var startTime = now()
// All timings will be relative to this request's startTime. In order to do this,
// we need to capture the wall-clock start time (via Date), immediately followed
// by the high-resolution timer (via now()). While these two won't be set
// at the _exact_ same time, they should be close enough to be able to calculate
// high-resolution, monotonically non-decreasing timestamps relative to startTime.
var startTime = new Date().getTime()
var startTimeNow = now()
}

@@ -758,6 +765,8 @@

if (self.timing) {
self.startTime = new Date().getTime()
self.timings = {
start: startTime
}
self.startTime = startTime
self.startTimeNow = startTimeNow
// Timing values will all be relative to startTime (by comparing to startTimeNow
// so we have an accurate clock)
self.timings = {}
}

@@ -780,7 +789,25 @@

self.req.on('socket', function(socket) {
// `._connecting` was the old property which was made public in node v6.1.0
var isConnecting = socket._connecting || socket.connecting
if (self.timing) {
self.timings.socket = now()
socket.on('connect', function() {
self.timings.connect = now()
})
self.timings.socket = now() - self.startTimeNow
if (isConnecting) {
var onLookupTiming = function() {
self.timings.lookup = now() - self.startTimeNow
}
var onConnectTiming = function() {
self.timings.connect = now() - self.startTimeNow
}
socket.once('lookup', onLookupTiming)
socket.once('connect', onConnectTiming)
// clean up timing event listeners if needed on error
self.req.once('error', function() {
socket.removeListener('lookup', onLookupTiming)
socket.removeListener('connect', onConnectTiming)
})
}
}

@@ -804,4 +831,2 @@

}
// `._connecting` was the old property which was made public in node v6.1.0
var isConnecting = socket._connecting || socket.connecting
if (timeout !== undefined) {

@@ -872,3 +897,3 @@ // Only start the connection timer if we're actually connecting a new

if (self.timing) {
self.timings.response = now()
self.timings.response = now() - self.startTimeNow
}

@@ -879,14 +904,24 @@

if (self.timing) {
self.timings.end = now()
self.timings.end = now() - self.startTimeNow
response.timingStart = self.startTime
self.timings.dns = self.timings.socket - self.timings.start
self.timings.tcp = self.timings.connect - self.timings.socket
self.timings.firstByte = self.timings.response - self.timings.connect
self.timings.download = self.timings.end - self.timings.response
self.timings.total = self.timings.end - self.timings.start
// fill in the blanks for any periods that didn't trigger, such as
// no lookup or connect due to keep alive
if (!self.timings.socket) {
self.timings.socket = 0
}
if (!self.timings.lookup) {
self.timings.lookup = self.timings.socket
}
if (!self.timings.connect) {
self.timings.connect = self.timings.lookup
}
if (!self.timings.response) {
self.timings.response = self.timings.connect
}
debug('elapsed time', self.timings.total)
debug('elapsed time', self.timings.end)
// elapsedTime includes all redirects
self.elapsedTime += Math.round(self.timings.total)
self.elapsedTime += Math.round(self.timings.end)

@@ -898,2 +933,12 @@ // NOTE: elapsedTime is deprecated in favor of .timings

response.timings = self.timings
// pre-calculate phase timings as well
response.timingPhases = {
wait: self.timings.socket,
dns: self.timings.lookup - self.timings.socket,
tcp: self.timings.connect - self.timings.lookup,
firstByte: self.timings.response - self.timings.connect,
download: self.timings.end - self.timings.response,
total: self.timings.end
}
}

@@ -1133,3 +1178,3 @@ debug('response end', self.uri.href, response.statusCode, response.headers)

if (typeof response.body === 'undefined' && !self._json) {
response.body = self.encoding === null ? new Buffer(0) : ''
response.body = self.encoding === null ? Buffer.alloc(0) : ''
}

@@ -1136,0 +1181,0 @@ self.emit('complete', response, response.body)

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc