summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/socks-proxy-agent/node_modules/agent-base/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/socks-proxy-agent/node_modules/agent-base/README.md')
-rw-r--r--deps/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/socks-proxy-agent/node_modules/agent-base/README.md31
1 files changed, 23 insertions, 8 deletions
diff --git a/deps/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/socks-proxy-agent/node_modules/agent-base/README.md b/deps/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/socks-proxy-agent/node_modules/agent-base/README.md
index 616b90cdbf..64175a43a4 100644
--- a/deps/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/socks-proxy-agent/node_modules/agent-base/README.md
+++ b/deps/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/socks-proxy-agent/node_modules/agent-base/README.md
@@ -1,6 +1,6 @@
agent-base
==========
-### Turn a function into an `http.Agent` instance
+### Turn a function into an [`http.Agent`][http.Agent] instance
[![Build Status](https://travis-ci.org/TooTallNate/node-agent-base.svg?branch=master)](https://travis-ci.org/TooTallNate/node-agent-base)
This module provides an `http.Agent` generator. That is, you pass it an async
@@ -34,7 +34,7 @@ Example
Here's a minimal example that creates a new `net.Socket` connection to the server
for every HTTP request (i.e. the equivalent of `agent: false` option):
-``` js
+```js
var net = require('net');
var tls = require('tls');
var url = require('url');
@@ -42,10 +42,10 @@ var http = require('http');
var agent = require('agent-base');
var endpoint = 'http://nodejs.org/api/';
-var opts = url.parse(endpoint);
+var parsed = url.parse(endpoint);
// This is the important part!
-opts.agent = agent(function (req, opts, fn) {
+parsed.agent = agent(function (req, opts) {
var socket;
// `secureEndpoint` is true when using the https module
if (opts.secureEndpoint) {
@@ -53,26 +53,40 @@ opts.agent = agent(function (req, opts, fn) {
} else {
socket = net.connect(opts);
}
- fn(null, socket);
+ return socket;
});
// Everything else works just like normal...
-http.get(opts, function (res) {
+http.get(parsed, function (res) {
console.log('"response" event!', res.headers);
res.pipe(process.stdout);
});
```
+You can also return a Promise or use an `async` function:
+
+```js
+agent(async function (req, opts) {
+ await sleep(1000);
+ // etc…
+});
+```
+
+
API
---
-## Agent(Function callback) → http.Agent
+## Agent(Function callback[, Object options]) → [http.Agent][]
Creates a base `http.Agent` that will execute the callback function `callback`
for every HTTP request that it is used as the `agent` for. The callback function
is responsible for creating a `stream.Duplex` instance of some kind that will be
used as the underlying socket in the HTTP request.
+The `options` object accepts the following properties:
+
+ * `timeout` - Number - Timeout for the `callback()` function in milliseconds. Defaults to Infinity (optional).
+
The callback function should have the following signature:
### callback(http.ClientRequest req, Object options, Function cb) → undefined
@@ -86,7 +100,7 @@ the callback function `cb` once created, and the HTTP request will
continue to proceed.
If the `https` module is used to invoke the HTTP request, then the
-`secureEndpoint` property on `options` will be set to `true`.
+`secureEndpoint` property on `options` _will be set to `true`_.
License
@@ -119,3 +133,4 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
[https-proxy-agent]: https://github.com/TooTallNate/node-https-proxy-agent
[pac-proxy-agent]: https://github.com/TooTallNate/node-pac-proxy-agent
[socks-proxy-agent]: https://github.com/TooTallNate/node-socks-proxy-agent
+[http.Agent]: https://nodejs.org/api/http.html#http_class_http_agent