Deprecated!

As of Feb 11th 2020, request is fully deprecated. No new changes are expected to land. In fact, none have landed for some time.

For more information about why request is deprecated and possible alternatives refer to this issue.

Request - Simplified HTTP client

npm package

Build status Coverage Coverage Dependency Status Known Vulnerabilities Gitter

Super simple to use

Request is designed to be the simplest way possible to make http calls. It supports HTTPS and follows redirects by default.

const request = require('request');
request('http://www.google.com', function (error, response, body) {
  console.error('error:', error); // Print the error if one occurred
  console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
  console.log('body:', body); // Print the HTML for the Google homepage.
});

Table of contents

Request also offers convenience methods like request.defaults and request.post, and there are lots of usage examples and several debugging techniques.


Streaming

You can stream any response to a file stream.

request('http://google.com/doodle.png').pipe(fs.createWriteStream('doodle.png'))

You can also stream a file to a PUT or POST request. This method will also check the file extension against a mapping of file extensions to content-types (in this case application/json) and use the proper content-type in the PUT request (if the headers don’t already provide one).

fs.createReadStream('file.json').pipe(request.put('http://mysite.com/obj.json'))

Request can also pipe to itself. When doing so, content-type and content-length are preserved in the PUT headers.

request.get('http://google.com/img.png').pipe(request.put('http://mysite.com/img.png'))

Request emits a "response" event when a response is received. The response argument will be an instance of http.IncomingMessage.

request
  .get('http://google.com/img.png')
  .on('response', function(response) {
    console.log(response.statusCode) // 200
    console.log(response.headers['content-type']) // 'image/png'
  })
  .pipe(request.put('http://mysite.com/img.png'))

To easily handle errors when streaming requests, listen to the error event before piping:

request
  .get('http://mysite.com/doodle.png')
  .on('error', function(err) {
    console.error(err)
  })
  .pipe(fs.createWriteStream('doodle.png'))

Now let’s get fancy.

http.createServer(function (req, resp) {
  if (req.url === '/doodle.png') {
    if (req.method === 'PUT') {
      req.pipe(request.put('http://mysite.com/doodle.png'))
    } else if (req.method === 'GET' || req.method === 'HEAD') {
      request.get('http://mysite.com/doodle.png').pipe(resp)
    }
  }
})

You can also pipe() from http.ServerRequest instances, as well as to http.ServerResponse instances. The HTTP method, headers, and entity-body data will be sent. Which means that, if you don't really care about security, you can do:

http.createServer(function (req, resp) {
  if (req.url === '/doodle.png') {
    const x = request('http://mysite.com/doodle.png')
    req.pipe(x)
    x.pipe(resp)
  }
})

And since pipe() returns the destination stream in ≥ Node 0.5.x you can do one line proxying. :)

req.pipe(request('http://mysite.com/doodle.png')).pipe(resp)

Also, none of this new functionality conflicts with requests previous features, it just expands them.

const r = request.defaults({'proxy':'http://localproxy.com'})

http.createServer(function (req, resp) {
  if (req.url === '/doodle.png') {
    r.get('http://google.com/doodle.png').pipe(resp)
  }
})

You can still use intermediate proxies, the requests will still follow HTTP forwards, etc.

back to top


Promises & Async/Await

request supports both streaming and callback interfaces natively. If you'd like request to return a Promise instead, you can use an alternative interface wrapper for request. These wrappers can be useful if you prefer to work with Promises, or if you'd like to use async/await in ES2017.

Several alternative interfaces are provided by the request team, including:

Also, util.promisify, which is available from Node.js v8.0 can be used to convert a regular function that takes a callback to return a promise instead.

back to top


Forms

request supports application/x-www-form-urlencoded and multipart/form-data form uploads. For multipart/related refer to the multipart API.

application/x-www-form-urlencoded (URL-Encoded Forms)

URL-encoded forms are simple.

request.post('http://service.com/upload', {form:{key:'value'}})
// or
request.post('http://service.com/upload').form({key:'value'})
// or
request.post({url:'http://service.com/upload', form: {key:'value'}}, function(err,httpResponse,body){ /* ... */ })

multipart/form-data (Multipart Form Uploads)

For multipart/form-data we use the form-data library by @felixge. For the most cases, you can pass your upload form data via the formData option.

const formData = {
  // Pass a simple key-value pair
  my_field: 'my_value',
  // Pass data via Buffers
  my_buffer: Buffer.from([1, 2, 3]),
  // Pass data via Streams
  my_file: fs.createReadStream(__dirname + '/unicycle.jpg'),
  // Pass multiple values /w an Array
  attachments: [
    fs.createReadStream(__dirname + '/attachment1.jpg'),
    fs.createReadStream(__dirname + '/attachment2.jpg')
  ],
  // Pass optional meta-data with an 'options' object with style: {value: DATA, options: OPTIONS}
  // Use case: for some types of streams, you'll need to provide "file"-related information manually.
  // See the `form-data` README for more information about options: https://github.com/form-data/form-data
  custom_file: {
    value:  fs.createReadStream('/dev/urandom'),
    options: {
      filename: 'topsecret.jpg',
      contentType: 'image/jpeg'
    }
  }
};
request.post({url:'http://service.com/upload', formData: formData}, function optionalCallback(err, httpResponse, body) {
  if (err) {
    return console.error('upload failed:', err);
  }
  console.log('Upload successful!  Server responded with:', body);
});

For advanced cases, you can access the form-data object itself via r.form(). This can be modified until the request is fired on the next cycle of the event-loop. (Note that this calling form() will clear the currently set form data for that request.)

// NOTE: Advanced use-case, for normal use see 'formData' usage above
const r = request.post('http://service.com/upload', function optionalCallback(err, httpResponse, body) {...})
const form = r.form();
form.append('my_field', 'my_value');
form.append('my_buffer', Buffer.from([1, 2, 3]));
form.append('custom_file', fs.createReadStream(__dirname + '/unicycle.jpg'), {filename: 'unicycle.jpg'});

See the form-data README for more information & examples.

multipart/related

Some variations in different HTTP implementations require a newline/CRLF before, after, or both before and after the boundary of a multipart/related request (using the multipart option). This has been observed in the .NET WebAPI version 4.0. You can turn on a boundary preambleCRLF or postamble by passing them as true to your request options.

  request({
    method: 'PUT',
    preambleCRLF: true,
    postambleCRLF: true,
    uri: 'http://service.com/upload',
    multipart: [
      {
        'content-type': 'application/json',
        body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}})
      },
      { body: 'I am an attachment' },
      { body: fs.createReadStream('image.png') }
    ],
    // alternatively pass an object containing additional options
    multipart: {
      chunked: false,
      data: [
        {
          'content-type': 'application/json',
          body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}})
        },
        { body: 'I am an attachment' }
      ]
    }
  },
  function (error, response, body) {
    if (error) {
      return console.error('upload failed:', error);
    }
    console.log('Upload successful!  Server responded with:', body);
  })

back to top


HTTP Authentication

request.get('http://some.server.com/').auth('username', 'password', false);
// or
request.get('http://some.server.com/', {
  'auth': {
    'user': 'username',
    'pass': 'password',
    'sendImmediately': false
  }
});
// or
request.get('http://some.server.com/').auth(null, null, true, 'bearerToken');
// or
request.get('http://some.server.com/', {
  'auth': {
    'bearer': 'bearerToken'
  }
});

If passed as an option, auth should be a hash containing values:

  • user || username
  • pass || password
  • sendImmediately (optional)
  • bearer (optional)

The method form takes parameters auth(username, password, sendImmediately, bearer).

sendImmediately defaults to true, which causes a basic or bearer authentication header to be sent. If sendImmediately is false, then request will retry with a proper authentication header after receiving a 401 response from the server (which must contain a WWW-Authenticate header indicating the required authentication method).

Note that you can also specify basic authentication using the URL itself, as detailed in RFC 1738. Simply pass the user:password before the host with an @ sign:

const username = 'username',
    password = 'password',
    url = 'http://' + username + ':' + password + '@some.server.com';

request({url}, function (error, response, body) {
   // Do more stuff with 'body' here
});

Digest authentication is supported, but it only works with sendImmediately set to false; otherwise request will send basic authentication on the initial request, which will probably cause the request to fail.

Bearer authentication is supported, and is activated when the bearer value is available. The value may be either a String or a Function returning a String. Using a function to supply the bearer token is particularly useful if used in conjunction with defaults to allow a single function to supply the last known token at the time of sending a request, or to compute one on the fly.

back to top


Custom HTTP Headers

HTTP Headers, such as User-Agent, can be set in the options object. In the example below, we call the github API to find out the number of stars and forks for the request repository. This requires a custom User-Agent header as well as https.

const request = require('request');

const options = {
  url: 'https://api.github.com/repos/request/request',
  headers: {
    'User-Agent': 'request'
  }
};

function callback(error, response, body) {
  if (!error && response.statusCode == 200) {
    const info = JSON.parse(body);
    console.log(info.stargazers_count + " Stars");
    console.log(info.forks_count + " Forks");
  }
}

request(options, callback);

back to top


OAuth Signing

OAuth version 1.0 is supported. The default signing algorithm is HMAC-SHA1:

// OAuth1.0 - 3-legged server side flow (Twitter example)
// step 1
const qs = require('querystring')
  , oauth =
    { callback: 'http://mysite.com/callback/'
    , consumer_key: CONSUMER_KEY
    , consumer_secret: CONSUMER_SECRET
    }
  , url = 'https://api.twitter.com/oauth/request_token'
  ;
request.post({url:url, oauth:oauth}, function (e, r, body) {
  // Ideally, you would take the body in the response
  // and construct a URL that a user clicks on (like a sign in button).
  // The verifier is only available in the response after a user has
  // verified with twitter that they are authorizing your app.

  // step 2
  const req_data = qs.parse(body)
  const uri = 'https://api.twitter.com/oauth/authenticate'
    + '?' + qs.stringify({oauth_token: req_data.oauth_token})
  // redirect the user to the authorize uri

  // step 3
  // after the user is redirected back to your server
  const auth_data = qs.parse(body)
    , oauth =
      { consumer_key: CONSUMER_KEY
      , consumer_secret: CONSUMER_SECRET
      , token: auth_data.oauth_token
      , token_secret: req_data.oauth_token_secret
      , verifier: auth_data.oauth_verifier
      }
    , url = 'https://api.twitter.com/oauth/access_token'
    ;
  request.post({url:url, oauth:oauth}, function (e, r, body) {
    // ready to make signed requests on behalf of the user
    const perm_data = qs.parse(body)
      , oauth =
        { consumer_key: CONSUMER_KEY
        , consumer_secret: CONSUMER_SECRET
        , token: perm_data.oauth_token
        , token_secret: perm_data.oauth_token_secret
        }
      , url = 'https://api.twitter.com/1.1/users/show.json'
      , qs =
        { screen_name: perm_data.screen_name
        , user_id: perm_data.user_id
        }
      ;
    request.get({url:url, oauth:oauth, qs:qs, json:true}, function (e, r, user) {
      console.log(user)
    })
  })
})

For RSA-SHA1 signing, make the following changes to the OAuth options object:

  • Pass signature_method : 'RSA-SHA1'
  • Instead of consumer_secret, specify a private_key string in PEM format

For PLAINTEXT signing, make the following changes to the OAuth options object:

  • Pass signature_method : 'PLAINTEXT'

To send OAuth parameters via query params or in a post body as described in The Consumer Request Parameters section of the oauth1 spec:

  • Pass transport_method : 'query' or transport_method : 'body' in the OAuth options object.
  • transport_method defaults to 'header'

To use Request Body Hash you can either

  • Manually generate the body hash and pass it as a string body_hash: '...'
  • Automatically generate the body hash by passing body_hash: true

back to top


Proxies

If you specify a proxy option, then the request (and any subsequent redirects) will be sent via a connection to the proxy server.

If your endpoint is an https url, and you are using a proxy, then request will send a CONNECT request to the proxy server first, and then use the supplied connection to connect to the endpoint.

That is, first it will make a request like:

HTTP/1.1 CONNECT endpoint-server.com:80
Host: proxy-server.com
User-Agent: whatever user agent you specify

and then the proxy server make a TCP connection to endpoint-server on port 80, and return a response that looks like:

HTTP/1.1 200 OK

At this point, the connection is left open, and the client is communicating directly with the endpoint-server.com machine.

See the wikipedia page on HTTP Tunneling for more information.

By default, when proxying http traffic, request will simply make a standard proxied http request. This is done by making the url section of the initial line of the request a fully qualified url to the endpoint.

For example, it will make a single request that looks like:

HTTP/1.1 GET http://endpoint-server.com/some-url
Host: proxy-server.com
Other-Headers: all go here

request body or whatever

Because a pure "http over http" tunnel offers no additional security or other features, it is generally simpler to go with a straightforward HTTP proxy in this case. However, if you would like to force a tunneling proxy, you may set the tunnel option to true.

You can also make a standard proxied http request by explicitly setting tunnel : false, but note that this will allow the proxy to see the traffic to/from the destination server.

If you are using a tunneling proxy, you may set the proxyHeaderWhiteList to share certain headers with the proxy.

You can also set the proxyHeaderExclusiveList to share certain headers only with the proxy and not with destination host.

By default, this set is:

accept
accept-charset
accept-encoding
accept-language
accept-ranges
cache-control
content-encoding
content-language
content-length
content-location
content-md5
content-range
content-type
connection
date
expect
max-forwards
pragma
proxy-authorization
referer
te
transfer-encoding
user-agent
via

Note that, when using a tunneling proxy, the proxy-authorization header and any headers from custom proxyHeaderExclusiveList are never sent to the endpoint server, but only to the proxy server.

Controlling proxy behaviour using environment variables

The following environment variables are respected by request:

  • HTTP_PROXY / http_proxy
  • HTTPS_PROXY / https_proxy
  • NO_PROXY / no_proxy

When HTTP_PROXY / http_proxy are set, they will be used to proxy non-SSL requests that do not have an explicit proxy configuration option present. Similarly, HTTPS_PROXY / https_proxy will be respected for SSL requests that do not have an explicit proxy configuration option. It is valid to define a proxy in one of the environment variables, but then override it for a specific request, using the proxy configuration option. Furthermore, the proxy configuration option can be explicitly set to false / null to opt out of proxying altogether for that request.

request is also aware of the NO_PROXY/no_proxy environment variables. These variables provide a granular way to opt out of proxying, on a per-host basis. It should contain a comma separated list of hosts to opt out of proxying. It is also possible to opt of proxying when a particular destination port is used. Finally, the variable may be set to * to opt out of the implicit proxy configuration of the other environment variables.

Here's some examples of valid no_proxy values:

  • google.com - don't proxy HTTP/HTTPS requests to Google.
  • google.com:443 - don't proxy HTTPS requests to Google, but do proxy HTTP requests to Google.
  • google.com:443, yahoo.com:80 - don't proxy HTTPS requests to Google, and don't proxy HTTP requests to Yahoo!
  • * - ignore https_proxy/http_proxy environment variables altogether.

back to top


UNIX Domain Sockets

request supports making requests to UNIX Domain Sockets. To make one, use the following URL scheme:

/* Pattern */ 'http://unix:SOCKET:PATH'
/* Example */ request.get('http://unix:/absolute/path/to/unix.socket:/request/path')

Note: The SOCKET path is assumed to be absolute to the root of the host file system.

back to top


TLS/SSL Protocol

TLS/SSL Protocol options, such as cert, key and passphrase, can be set directly in options object, in the agentOptions property of the options object, or even in https.globalAgent.options. Keep in mind that, although agentOptions allows for a slightly wider range of configurations, the recommended way is via options object directly, as using agentOptions or https.globalAgent.options would not be applied in the same way in proxied environments (as data travels through a TLS connection instead of an http/https agent).

const fs = require('fs')
    , path = require('path')
    , certFile = path.resolve(__dirname, 'ssl/client.crt')
    , keyFile = path.resolve(__dirname, 'ssl/client.key')
    , caFile = path.resolve(__dirname, 'ssl/ca.cert.pem')
    , request = require('request');

const options = {
    url: 'https://api.some-server.com/',
    cert: fs.readFileSync(certFile),
    key: fs.readFileSync(keyFile),
    passphrase: 'password',
    ca: fs.readFileSync(caFile)
};

request.get(options);

Using options.agentOptions

In the example below, we call an API that requires client side SSL certificate (in PEM format) with passphrase protected private key (in PEM format) and disable the SSLv3 protocol:

const fs = require('fs')
    , path = require('path')
    , certFile = path.resolve(__dirname, 'ssl/client.crt')
    , keyFile = path.resolve(__dirname, 'ssl/client.key')
    , request = require('request');

const options = {
    url: 'https://api.some-server.com/',
    agentOptions: {
        cert: fs.readFileSync(certFile),
        key: fs.readFileSync(keyFile),
        // Or use `pfx` property replacing `cert` and `key` when using private key, certificate and CA certs in PFX or PKCS12 format:
        // pfx: fs.readFileSync(pfxFilePath),
        passphrase: 'password',
        securityOptions: 'SSL_OP_NO_SSLv3'
    }
};

request.get(options);

It is able to force using SSLv3 only by specifying secureProtocol:

request.get({
    url: 'https://api.some-server.com/',
    agentOptions: {
        secureProtocol: 'SSLv3_method'
    }
});

It is possible to accept other certificates than those signed by generally allowed Certificate Authorities (CAs). This can be useful, for example, when using self-signed certificates. To require a different root certificate, you can specify the signing CA by adding the contents of the CA's certificate file to the agentOptions. The certificate the domain presents must be signed by the root certificate specified:

request.get({
    url: 'https://api.some-server.com/',
    agentOptions: {
        ca: fs.readFileSync('ca.cert.pem')
    }
});

The ca value can be an array of certificates, in the event you have a private or internal corporate public-key infrastructure hierarchy. For example, if you want to connect to https://api.some-server.com which presents a key chain consisting of:

  1. its own public key, which is signed by:
  2. an intermediate "Corp Issuing Server", that is in turn signed by:
  3. a root CA "Corp Root CA";

you can configure your request as follows:

request.get({
    url: 'https://api.some-server.com/',
    agentOptions: {
        ca: [
          fs.readFileSync('Corp Issuing Server.pem'),
          fs.readFileSync('Corp Root CA.pem')
        ]
    }
});

back to top


Support for HAR 1.2

The options.har property will override the values: url, method, qs, headers, form, formData, body, json, as well as construct multipart data and read files from disk when request.postData.params[].fileName is present without a matching value.

A validation step will check if the HAR Request format matches the latest spec (v1.2) and will skip parsing if not matching.

  const request = require('request')
  request({
    // will be ignored
    method: 'GET',
    uri: 'http://www.google.com',

    // HTTP Archive Request Object
    har: {
      url: 'http://www.mockbin.com/har',
      method: 'POST',
      headers: [
        {
          name: 'content-type',
          value: 'application/x-www-form-urlencoded'
        }
      ],
      postData: {
        mimeType: 'application/x-www-form-urlencoded',
        params: [
          {
            name: 'foo',
            value: 'bar'
          },
          {
            name: 'hello',
            value: 'world'
          }
        ]
      }
    }
  })

  // a POST request will be sent to http://www.mockbin.com
  // with body an application/x-www-form-urlencoded body:
  // foo=bar&hello=world

back to top


request(options, callback)

The first argument can be either a url or an options object. The only required option is uri; all others are optional.

  • uri || url - fully qualified uri or a parsed url object from url.parse()
  • baseUrl - fully qualified uri string used as the base url. Most useful with request.defaults, for example when you want to do many requests to the same domain. If baseUrl is https://example.com/api/, then requesting /end/point?test=true will fetch https://example.com/api/end/point?test=true. When baseUrl is given, uri must also be a string.
  • method - http method (default: "GET")
  • headers - http headers (default: {})

  • qs - object containing querystring values to be appended to the uri
  • qsParseOptions - object containing options to pass to the qs.parse method. Alternatively pass options to the querystring.parse method using this format {sep:';', eq:':', options:{}}
  • qsStringifyOptions - object containing options to pass to the qs.stringify method. Alternatively pass options to the querystring.stringify method using this format {sep:';', eq:':', options:{}}. For example, to change the way arrays are converted to query strings using the qs module pass the arrayFormat option with one of indices|brackets|repeat
  • useQuerystring - if true, use querystring to stringify and parse querystrings, otherwise use qs (default: false). Set this option to true if you need arrays to be serialized as foo=bar&foo=baz instead of the default foo[0]=bar&foo[1]=baz.

  • body - entity body for PATCH, POST and PUT requests. Must be a Buffer, String or ReadStream. If json is true, then body must be a JSON-serializable object.
  • form - when passed an object or a querystring, this sets body to a querystring representation of value, and adds Content-type: application/x-www-form-urlencoded header. When passed no options, a FormData instance is returned (and is piped to request). See "Forms" section above.
  • formData - data to pass for a multipart/form-data request. See Forms section above.
  • multipart - array of objects which contain their own headers and body attributes. Sends a multipart/related request. See Forms section above.
    • Alternatively you can pass in an object {chunked: false, data: []} where chunked is used to specify whether the request is sent in chunked transfer encoding In non-chunked requests, data items with body streams are not allowed.
  • preambleCRLF - append a newline/CRLF before the boundary of your multipart/form-data request.
  • postambleCRLF - append a newline/CRLF at the end of the boundary of your multipart/form-data request.
  • json - sets body to JSON representation of value and adds Content-type: application/json header. Additionally, parses the response body as JSON.
  • jsonReviver - a reviver function that will be passed to JSON.parse() when parsing a JSON response body.
  • jsonReplacer - a replacer function that will be passed to JSON.stringify() when stringifying a JSON request body.

  • auth - a hash containing values user || username, pass || password, and sendImmediately (optional). See documentation above.
  • oauth - options for OAuth HMAC-SHA1 signing. See documentation above.
  • hawk - options for Hawk signing. The credentials key must contain the necessary signing info, see hawk docs for details.
  • aws - object containing AWS signing information. Should have the properties key, secret, and optionally session (note that this only works for services that require session as part of the canonical string). Also requires the property bucket, unless you’re specifying your bucket as part of the path, or the request doesn’t use a bucket (i.e. GET Services). If you want to use AWS sign version 4 use the parameter sign_version with value 4 otherwise the default is version 2. If you are using SigV4, you can also include a service property that specifies the service name. Note: you need to npm install aws4 first.
  • httpSignature - options for the HTTP Signature Scheme using Joyent's library. The keyId and key properties must be specified. See the docs for other options.

  • followRedirect - follow HTTP 3xx responses as redirects (default: true). This property can also be implemented as function which gets response object as a single argument and should return true if redirects should continue or false otherwise.
  • followAllRedirects - follow non-GET HTTP 3xx responses as redirects (default: false)
  • followOriginalHttpMethod - by default we redirect to HTTP method GET. you can enable this property to redirect to the original HTTP method (default: false)
  • maxRedirects - the maximum number of redirects to follow (default: 10)
  • removeRefererHeader - removes the referer header when a redirect happens (default: false). Note: if true, referer header set in the initial request is preserved during redirect chain.

  • encoding - encoding to be used on setEncoding of response data. If null, the body is returned as a Buffer. Anything else (including the default value of undefined) will be passed as the encoding parameter to toString() (meaning this is effectively utf8 by default). (Note: if you expect binary data, you should set encoding: null.)
  • gzip - if true, add an Accept-Encoding header to request compressed content encodings from the server (if not already present) and decode supported content encodings in the response. Note: Automatic decoding of the response content is performed on the body data returned through request (both through the request stream and passed to the callback function) but is not performed on the response stream (available from the response event) which is the unmodified http.IncomingMessage object which may contain compressed data. See example below.
  • jar - if true, remember cookies for future use (or define your custom cookie jar; see examples section)

  • agent - http(s).Agent instance to use
  • agentClass - alternatively specify your agent's class name
  • agentOptions - and pass its options. Note: for HTTPS see tls API doc for TLS/SSL options and the documentation above.
  • forever - set to true to use the forever-agent Note: Defaults to http(s).Agent({keepAlive:true}) in node 0.12+
  • pool - an object describing which agents to use for the request. If this option is omitted the request will use the global agent (as long as your options allow for it). Otherwise, request will search the pool for your custom agent. If no custom agent is found, a new agent will be created and added to the pool. Note: pool is used only when the agent option is not specified.
    • A maxSockets property can also be provided on the pool object to set the max number of sockets for all agents created (ex: pool: {maxSockets: Infinity}).
    • Note that if you are sending multiple requests in a loop and creating multiple new pool objects, maxSockets will not work as intended. To work around this, either use request.defaults with your pool options or create the pool object with the maxSockets property outside of the loop.
  • timeout - integer containing number of milliseconds, controls two timeouts.
    • Read timeout: Time to wait for a server to send response headers (and start the response body) before aborting the request.
    • Connection timeout: Sets the socket to timeout after timeout milliseconds of inactivity. Note that increasing the timeout beyond the OS-wide TCP connection timeout will not have any effect (the default in Linux can be anywhere from 20-120 seconds)

  • localAddress - local interface to bind for network connections.
  • proxy - an HTTP proxy to be used. Supports proxy Auth with Basic Auth, identical to support for the url parameter (by embedding the auth info in the uri)
  • strictSSL - if true, requires SSL certificates be valid. Note: to use your own certificate authority, you need to specify an agent that was created with that CA as an option.
  • tunnel - controls the behavior of HTTP CONNECT tunneling as follows:
    • undefined (default) - true if the destination is https, false otherwise
    • true - always tunnel to the destination by making a CONNECT request to the proxy
    • false - request the destination as a GET request.
  • proxyHeaderWhiteList - a whitelist of headers to send to a tunneling proxy.
  • proxyHeaderExclusiveList - a whitelist of headers to send exclusively to a tunneling proxy and not to destination.

  • 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 module's socket event fires. This happens when the socket is assigned to the request.
      • lookup Relative timestamp when the net module's lookup event fires. This happens when the DNS has been resolved.
      • connect: Relative timestamp when the net module's connect event fires. This happens when the server acknowledges the TCP connection.
      • response: Relative timestamp when the http 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)
  • har - a HAR 1.2 Request Object, will be processed from HAR format into options overwriting matching values (see the HAR 1.2 section for details)

  • callback - alternatively pass the request's callback in the options object

The callback argument gets 3 arguments:

  1. An error when applicable (usually from http.ClientRequest object)
  2. An http.IncomingMessage object (Response object)
  3. The third is the response body (String or Buffer, or JSON object if the json option is supplied)

back to top


Convenience methods

There are also shorthand methods for different HTTP METHODs and some other conveniences.

request.defaults(options)

This method returns a wrapper around the normal request API that defaults to whatever options you pass to it.

Note: request.defaults() does not modify the global request API; instead, it returns a wrapper that has your default settings applied to it.

Note: You can call .defaults() on the wrapper that is returned from request.defaults to add/override defaults that were previously defaulted.

For example:

//requests using baseRequest() will set the 'x-token' header
const baseRequest = request.defaults({
  headers: {'x-token': 'my-token'}
})

//requests using specialRequest() will include the 'x-token' header set in
//baseRequest and will also include the 'special' header
const specialRequest = baseRequest.defaults({
  headers: {special: 'special value'}
})

request.METHOD()

These HTTP method convenience functions act just like request() but with a default method already set for you:

  • request.get(): Defaults to method: "GET".
  • request.post(): Defaults to method: "POST".
  • request.put(): Defaults to method: "PUT".
  • request.patch(): Defaults to method: "PATCH".
  • request.del() / request.delete(): Defaults to method: "DELETE".
  • request.head(): Defaults to method: "HEAD".
  • request.options(): Defaults to method: "OPTIONS".

request.cookie()

Function that creates a new cookie.

request.cookie('key1=value1')

request.jar()

Function that creates a new cookie jar.

request.jar()

response.caseless.get('header-name')

Function that returns the specified response header field using a case-insensitive match

request('http://www.google.com', function (error, response, body) {
  // print the Content-Type header even if the server returned it as 'content-type' (lowercase)
  console.log('Content-Type is:', response.caseless.get('Content-Type')); 
});

back to top


Debugging

There are at least three ways to debug the operation of request:

  1. Launch the node process like NODE_DEBUG=request node script.js (lib,request,otherlib works too).

  2. Set require('request').debug = true at any time (this does the same thing as #1).

  3. Use the request-debug module to view request and response headers and bodies.

back to top


Timeouts

Most requests to external servers should have a timeout attached, in case the server is not responding in a timely manner. Without a timeout, your code may have a socket open/consume resources for minutes or more.

There are two main types of timeouts: connection timeouts and read timeouts. A connect timeout occurs if the timeout is hit while your client is attempting to establish a connection to a remote machine (corresponding to the connect() call on the socket). A read timeout occurs any time the server is too slow to send back a part of the response.

These two situations have widely different implications for what went wrong with the request, so it's useful to be able to distinguish them. You can detect timeout errors by checking err.code for an 'ETIMEDOUT' value. Further, you can detect whether the timeout was a connection timeout by checking if the err.connect property is set to true.

request.get('http://10.255.255.1', {timeout: 1500}, function(err) {
    console.log(err.code === 'ETIMEDOUT');
    // Set to `true` if the timeout was a connection timeout, `false` or
    // `undefined` otherwise.
    console.log(err.connect === true);
    process.exit(0);
});

Examples:

  const request = require('request')
    , rand = Math.floor(Math.random()*100000000).toString()
    ;
  request(
    { method: 'PUT'
    , uri: 'http://mikeal.iriscouch.com/testjs/' + rand
    , multipart:
      [ { 'content-type': 'application/json'
        ,  body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}})
        }
      , { body: 'I am an attachment' }
      ]
    }
  , function (error, response, body) {
      if(response.statusCode == 201){
        console.log('document saved as: http://mikeal.iriscouch.com/testjs/'+ rand)
      } else {
        console.log('error: '+ response.statusCode)
        console.log(body)
      }
    }
  )

For backwards-compatibility, response compression is not supported by default. To accept gzip-compressed responses, set the gzip option to true. Note that the body data passed through request is automatically decompressed while the response object is unmodified and will contain compressed data if the server sent a compressed response.

  const request = require('request')
  request(
    { method: 'GET'
    , uri: 'http://www.google.com'
    , gzip: true
    }
  , function (error, response, body) {
      // body is the decompressed response body
      console.log('server encoded the data as: ' + (response.headers['content-encoding'] || 'identity'))
      console.log('the decoded data is: ' + body)
    }
  )
  .on('data', function(data) {
    // decompressed data as it is received
    console.log('decoded chunk: ' + data)
  })
  .on('response', function(response) {
    // unmodified http.IncomingMessage object
    response.on('data', function(data) {
      // compressed data as it is received
      console.log('received ' + data.length + ' bytes of compressed data')
    })
  })

Cookies are disabled by default (else, they would be used in subsequent requests). To enable cookies, set jar to true (either in defaults or options).

const request = request.defaults({jar: true})
request('http://www.google.com', function () {
  request('http://images.google.com')
})

To use a custom cookie jar (instead of request’s global cookie jar), set jar to an instance of request.jar() (either in defaults or options)

const j = request.jar()
const request = request.defaults({jar:j})
request('http://www.google.com', function () {
  request('http://images.google.com')
})

OR

const j = request.jar();
const cookie = request.cookie('key1=value1');
const url = 'http://www.google.com';
j.setCookie(cookie, url);
request({url: url, jar: j}, function () {
  request('http://images.google.com')
})

To use a custom cookie store (such as a FileCookieStore which supports saving to and restoring from JSON files), pass it as a parameter to request.jar():

const FileCookieStore = require('tough-cookie-filestore');
// NOTE - currently the 'cookies.json' file must already exist!
const j = request.jar(new FileCookieStore('cookies.json'));
request = request.defaults({ jar : j })
request('http://www.google.com', function() {
  request('http://images.google.com')
})

The cookie store must be a tough-cookie store and it must support synchronous operations; see the CookieStore API docs for details.

To inspect your cookie jar after a request:

const j = request.jar()
request({url: 'http://www.google.com', jar: j}, function () {
  const cookie_string = j.getCookieString(url); // "key1=value1; key2=value2; ..."
  const cookies = j.getCookies(url);
  // [{key: 'key1', value: 'value1', domain: "www.google.com", ...}, ...]
})

back to top

request/request

{
"props": {
"initialPayload": {
"allShortcutsEnabled": false,
"path": "/",
"repo": {
"id": 1283503,
"defaultBranch": "master",
"name": "request",
"ownerLogin": "request",
"currentUserCanPush": false,
"isFork": false,
"isEmpty": false,
"createdAt": "2011-01-23T01:25:14.000Z",
"ownerAvatar": "https://avatars.githubusercontent.com/u/730467?v=4",
"public": true,
"private": false,
"isOrgOwned": true
},
"currentUser": null,
"refInfo": {
"name": "master",
"listCacheKey": "v0:1581438641.0",
"canEdit": false,
"refType": "branch",
"currentOid": "3c0cddc7c8eb60b470e9519da85896ed7ee0081e"
},
"tree": {
"items": [
{
"name": ".github",
"path": ".github",
"contentType": "directory"
},
{
"name": "examples",
"path": "examples",
"contentType": "directory"
},
{
"name": "lib",
"path": "lib",
"contentType": "directory"
},
{
"name": "tests",
"path": "tests",
"contentType": "directory"
},
{
"name": ".gitignore",
"path": ".gitignore",
"contentType": "file"
},
{
"name": ".travis.yml",
"path": ".travis.yml",
"contentType": "file"
},
{
"name": "CHANGELOG.md",
"path": "CHANGELOG.md",
"contentType": "file"
},
{
"name": "CONTRIBUTING.md",
"path": "CONTRIBUTING.md",
"contentType": "file"
},
{
"name": "LICENSE",
"path": "LICENSE",
"contentType": "file"
},
{
"name": "README.md",
"path": "README.md",
"contentType": "file"
},
{
"name": "codecov.yml",
"path": "codecov.yml",
"contentType": "file"
},
{
"name": "disabled.appveyor.yml",
"path": "disabled.appveyor.yml",
"contentType": "file"
},
{
"name": "index.js",
"path": "index.js",
"contentType": "file"
},
{
"name": "package.json",
"path": "package.json",
"contentType": "file"
},
{
"name": "release.sh",
"path": "release.sh",
"contentType": "file"
},
{
"name": "request.js",
"path": "request.js",
"contentType": "file"
}
],
"templateDirectorySuggestionUrl": null,
"readme": null,
"totalCount": 16,
"showBranchInfobar": false
},
"fileTree": null,
"fileTreeProcessingTime": null,
"foldersToFetch": [],
"treeExpanded": false,
"symbolsExpanded": false,
"isOverview": true,
"overview": {
"banners": {
"shouldRecommendReadme": false,
"isPersonalRepo": false,
"showUseActionBanner": false,
"actionSlug": null,
"actionId": null,
"showProtectBranchBanner": false,
"publishBannersInfo": {
"dismissActionNoticePath": "/settings/dismiss-notice/publish_action_from_repo",
"releasePath": "/request/request/releases/new?marketplace=true",
"showPublishActionBanner": false
},
"interactionLimitBanner": null,
"showInvitationBanner": false,
"inviterName": null
},
"codeButton": {
"contactPath": "/contact",
"isEnterprise": false,
"local": {
"protocolInfo": {
"httpAvailable": true,
"sshAvailable": null,
"httpUrl": "https://github.com/request/request.git",
"showCloneWarning": null,
"sshUrl": null,
"sshCertificatesRequired": null,
"sshCertificatesAvailable": null,
"ghCliUrl": "gh repo clone request/request",
"defaultProtocol": "http",
"newSshKeyUrl": "/settings/ssh/new",
"setProtocolPath": "/users/set_protocol"
},
"platformInfo": {
"cloneUrl": "https://desktop.github.com",
"showVisualStudioCloneButton": false,
"visualStudioCloneUrl": "https://windows.github.com",
"showXcodeCloneButton": false,
"xcodeCloneUrl": "https://developer.apple.com",
"zipballUrl": "/request/request/archive/refs/heads/master.zip"
}
},
"newCodespacePath": "/codespaces/new?hide_repo_select=true&repo=1283503"
},
"popovers": {
"rename": null,
"renamedParentRepo": null
},
"commitCount": "2,270",
"overviewFiles": [
{
"displayName": "README.md",
"repoName": "request",
"refName": "master",
"path": "README.md",
"preferredFileType": "readme",
"tabName": "README",
"richText": "<article class=\"markdown-body entry-content container-lg\" itemprop=\"text\"><div class=\"markdown-heading\" dir=\"auto\"><h1 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">Deprecated!</h1><a id=\"user-content-deprecated\" class=\"anchor\" aria-label=\"Permalink: Deprecated!\" href=\"#deprecated\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">As of Feb 11th 2020, request is fully deprecated. No new changes are expected to land. In fact, none have landed for some time.</p>\n<p dir=\"auto\">For more information about why request is deprecated and possible alternatives refer to\n<a href=\"https://github.com/request/request/issues/3142\" data-hovercard-type=\"issue\" data-hovercard-url=\"/request/request/issues/3142/hovercard\">this issue</a>.</p>\n<div class=\"markdown-heading\" dir=\"auto\"><h1 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">Request - Simplified HTTP client</h1><a id=\"user-content-request---simplified-http-client\" class=\"anchor\" aria-label=\"Permalink: Request - Simplified HTTP client\" href=\"#request---simplified-http-client\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\"><a href=\"https://nodei.co/npm/request/\" rel=\"nofollow\"><img src=\"https://camo.githubusercontent.com/5ded14db946dddf40f1ac597611f73722f591dc93d3816856d9485b7baa0c1b7/68747470733a2f2f6e6f6465692e636f2f6e706d2f726571756573742e706e673f646f776e6c6f6164733d7472756526646f776e6c6f616452616e6b3d747275652673746172733d74727565\" alt=\"npm package\" data-canonical-src=\"https://nodei.co/npm/request.png?downloads=true&amp;downloadRank=true&amp;stars=true\" style=\"max-width: 100%;\"></a></p>\n<p dir=\"auto\"><a href=\"https://travis-ci.org/request/request\" rel=\"nofollow\"><img src=\"https://camo.githubusercontent.com/0fd3ab86180c430bee1e103327970f60c42e73ddf5bad8af508b9315821cc837/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f726571756573742f726571756573742f6d61737465722e7376673f7374796c653d666c61742d737175617265\" alt=\"Build status\" data-canonical-src=\"https://img.shields.io/travis/request/request/master.svg?style=flat-square\" style=\"max-width: 100%;\"></a>\n<a href=\"https://codecov.io/github/request/request?branch=master\" rel=\"nofollow\"><img src=\"https://camo.githubusercontent.com/d8a139bc8ad50b8cecc6f5cbcc673c1be4a92de536f7a08bec476e352176767f/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f726571756573742f726571756573742e7376673f7374796c653d666c61742d737175617265\" alt=\"Coverage\" data-canonical-src=\"https://img.shields.io/codecov/c/github/request/request.svg?style=flat-square\" style=\"max-width: 100%;\"></a>\n<a href=\"https://coveralls.io/r/request/request\" rel=\"nofollow\"><img src=\"https://camo.githubusercontent.com/eb8ce31c7ba11557cfcfd10c2a953a2652bff00c845dd1d7719dc09f8954354d/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f726571756573742f726571756573742e7376673f7374796c653d666c61742d737175617265\" alt=\"Coverage\" data-canonical-src=\"https://img.shields.io/coveralls/request/request.svg?style=flat-square\" style=\"max-width: 100%;\"></a>\n<a href=\"https://david-dm.org/request/request\" rel=\"nofollow\"><img src=\"https://camo.githubusercontent.com/0e76d56cfe2e057ce97e4a5bd1abb6b538dd52f21a9c63332185a40b87d65686/68747470733a2f2f696d672e736869656c64732e696f2f64617669642f726571756573742f726571756573742e7376673f7374796c653d666c61742d737175617265\" alt=\"Dependency Status\" data-canonical-src=\"https://img.shields.io/david/request/request.svg?style=flat-square\" style=\"max-width: 100%;\"></a>\n<a href=\"https://snyk.io/test/npm/request\" rel=\"nofollow\"><img src=\"https://camo.githubusercontent.com/213e3f77d8d25afe3579c7b8081d3153702e3045e6c047f2fa92747a99ef36f0/68747470733a2f2f736e796b2e696f2f746573742f6e706d2f726571756573742f62616467652e7376673f7374796c653d666c61742d737175617265\" alt=\"Known Vulnerabilities\" data-canonical-src=\"https://snyk.io/test/npm/request/badge.svg?style=flat-square\" style=\"max-width: 100%;\"></a>\n<a href=\"https://gitter.im/request/request?utm_source=badge\" rel=\"nofollow\"><img src=\"https://camo.githubusercontent.com/5fbbd2290b3089b7b1d58b93e0a814c731f2338ae5e5f3c6ce4fcad0fa394b2b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6769747465722d6a6f696e5f636861742d626c75652e7376673f7374796c653d666c61742d737175617265\" alt=\"Gitter\" data-canonical-src=\"https://img.shields.io/badge/gitter-join_chat-blue.svg?style=flat-square\" style=\"max-width: 100%;\"></a></p>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">Super simple to use</h2><a id=\"user-content-super-simple-to-use\" class=\"anchor\" aria-label=\"Permalink: Super simple to use\" href=\"#super-simple-to-use\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">Request is designed to be the simplest way possible to make http calls. It supports HTTPS and follows redirects by default.</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"const request = require('request');\nrequest('http://www.google.com', function (error, response, body) {\n console.error('error:', error); // Print the error if one occurred\n console.log('statusCode:', response &amp;&amp; response.statusCode); // Print the response status code if a response was received\n console.log('body:', body); // Print the HTML for the Google homepage.\n});\"><pre><span class=\"pl-k\">const</span> <span class=\"pl-s1\">request</span> <span class=\"pl-c1\">=</span> <span class=\"pl-en\">require</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'request'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span>\n<span class=\"pl-s1\">request</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://www.google.com'</span><span class=\"pl-kos\">,</span> <span class=\"pl-k\">function</span> <span class=\"pl-kos\">(</span><span class=\"pl-s1\">error</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">response</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">body</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-smi\">console</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">error</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'error:'</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">error</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span> <span class=\"pl-c\">// Print the error if one occurred</span>\n <span class=\"pl-smi\">console</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">log</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'statusCode:'</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">response</span> <span class=\"pl-c1\">&amp;&amp;</span> <span class=\"pl-s1\">response</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">statusCode</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span> <span class=\"pl-c\">// Print the response status code if a response was received</span>\n <span class=\"pl-smi\">console</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">log</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'body:'</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">body</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span> <span class=\"pl-c\">// Print the HTML for the Google homepage.</span>\n<span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span></pre></div>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">Table of contents</h2><a id=\"user-content-table-of-contents\" class=\"anchor\" aria-label=\"Permalink: Table of contents\" href=\"#table-of-contents\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<ul dir=\"auto\">\n<li><a href=\"#streaming\">Streaming</a></li>\n<li><a href=\"#promises--asyncawait\">Promises &amp; Async/Await</a></li>\n<li><a href=\"#forms\">Forms</a></li>\n<li><a href=\"#http-authentication\">HTTP Authentication</a></li>\n<li><a href=\"#custom-http-headers\">Custom HTTP Headers</a></li>\n<li><a href=\"#oauth-signing\">OAuth Signing</a></li>\n<li><a href=\"#proxies\">Proxies</a></li>\n<li><a href=\"#unix-domain-sockets\">Unix Domain Sockets</a></li>\n<li><a href=\"#tlsssl-protocol\">TLS/SSL Protocol</a></li>\n<li><a href=\"#support-for-har-12\">Support for HAR 1.2</a></li>\n<li><a href=\"#requestoptions-callback\"><strong>All Available Options</strong></a></li>\n</ul>\n<p dir=\"auto\">Request also offers <a href=\"#convenience-methods\">convenience methods</a> like\n<code>request.defaults</code> and <code>request.post</code>, and there are\nlots of <a href=\"#examples\">usage examples</a> and several\n<a href=\"#debugging\">debugging techniques</a>.</p>\n<hr>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">Streaming</h2><a id=\"user-content-streaming\" class=\"anchor\" aria-label=\"Permalink: Streaming\" href=\"#streaming\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">You can stream any response to a file stream.</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"request('http://google.com/doodle.png').pipe(fs.createWriteStream('doodle.png'))\"><pre><span class=\"pl-en\">request</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://google.com/doodle.png'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">pipe</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">fs</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">createWriteStream</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'doodle.png'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">)</span></pre></div>\n<p dir=\"auto\">You can also stream a file to a PUT or POST request. This method will also check the file extension against a mapping of file extensions to content-types (in this case <code>application/json</code>) and use the proper <code>content-type</code> in the PUT request (if the headers don’t already provide one).</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"fs.createReadStream('file.json').pipe(request.put('http://mysite.com/obj.json'))\"><pre><span class=\"pl-s1\">fs</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">createReadStream</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'file.json'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">pipe</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">put</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://mysite.com/obj.json'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">)</span></pre></div>\n<p dir=\"auto\">Request can also <code>pipe</code> to itself. When doing so, <code>content-type</code> and <code>content-length</code> are preserved in the PUT headers.</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"request.get('http://google.com/img.png').pipe(request.put('http://mysite.com/img.png'))\"><pre><span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">get</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://google.com/img.png'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">pipe</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">put</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://mysite.com/img.png'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">)</span></pre></div>\n<p dir=\"auto\">Request emits a \"response\" event when a response is received. The <code>response</code> argument will be an instance of <a href=\"https://nodejs.org/api/http.html#http_class_http_incomingmessage\" rel=\"nofollow\">http.IncomingMessage</a>.</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"request\n .get('http://google.com/img.png')\n .on('response', function(response) {\n console.log(response.statusCode) // 200\n console.log(response.headers['content-type']) // 'image/png'\n })\n .pipe(request.put('http://mysite.com/img.png'))\"><pre><span class=\"pl-s1\">request</span>\n <span class=\"pl-kos\">.</span><span class=\"pl-en\">get</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://google.com/img.png'</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">.</span><span class=\"pl-en\">on</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'response'</span><span class=\"pl-kos\">,</span> <span class=\"pl-k\">function</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">response</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-smi\">console</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">log</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">response</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">statusCode</span><span class=\"pl-kos\">)</span> <span class=\"pl-c\">// 200</span>\n <span class=\"pl-smi\">console</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">log</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">response</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">headers</span><span class=\"pl-kos\">[</span><span class=\"pl-s\">'content-type'</span><span class=\"pl-kos\">]</span><span class=\"pl-kos\">)</span> <span class=\"pl-c\">// 'image/png'</span>\n <span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">.</span><span class=\"pl-en\">pipe</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">put</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://mysite.com/img.png'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">)</span></pre></div>\n<p dir=\"auto\">To easily handle errors when streaming requests, listen to the <code>error</code> event before piping:</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"request\n .get('http://mysite.com/doodle.png')\n .on('error', function(err) {\n console.error(err)\n })\n .pipe(fs.createWriteStream('doodle.png'))\"><pre><span class=\"pl-s1\">request</span>\n <span class=\"pl-kos\">.</span><span class=\"pl-en\">get</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://mysite.com/doodle.png'</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">.</span><span class=\"pl-en\">on</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'error'</span><span class=\"pl-kos\">,</span> <span class=\"pl-k\">function</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">err</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-smi\">console</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">error</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">err</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">.</span><span class=\"pl-en\">pipe</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">fs</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">createWriteStream</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'doodle.png'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">)</span></pre></div>\n<p dir=\"auto\">Now let’s get fancy.</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"http.createServer(function (req, resp) {\n if (req.url === '/doodle.png') {\n if (req.method === 'PUT') {\n req.pipe(request.put('http://mysite.com/doodle.png'))\n } else if (req.method === 'GET' || req.method === 'HEAD') {\n request.get('http://mysite.com/doodle.png').pipe(resp)\n }\n }\n})\"><pre><span class=\"pl-s1\">http</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">createServer</span><span class=\"pl-kos\">(</span><span class=\"pl-k\">function</span> <span class=\"pl-kos\">(</span><span class=\"pl-s1\">req</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">resp</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-k\">if</span> <span class=\"pl-kos\">(</span><span class=\"pl-s1\">req</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">url</span> <span class=\"pl-c1\">===</span> <span class=\"pl-s\">'/doodle.png'</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-k\">if</span> <span class=\"pl-kos\">(</span><span class=\"pl-s1\">req</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">method</span> <span class=\"pl-c1\">===</span> <span class=\"pl-s\">'PUT'</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-s1\">req</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">pipe</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">put</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://mysite.com/doodle.png'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">}</span> <span class=\"pl-k\">else</span> <span class=\"pl-k\">if</span> <span class=\"pl-kos\">(</span><span class=\"pl-s1\">req</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">method</span> <span class=\"pl-c1\">===</span> <span class=\"pl-s\">'GET'</span> <span class=\"pl-c1\">||</span> <span class=\"pl-s1\">req</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">method</span> <span class=\"pl-c1\">===</span> <span class=\"pl-s\">'HEAD'</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">get</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://mysite.com/doodle.png'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">pipe</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">resp</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">}</span>\n <span class=\"pl-kos\">}</span>\n<span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span></pre></div>\n<p dir=\"auto\">You can also <code>pipe()</code> from <code>http.ServerRequest</code> instances, as well as to <code>http.ServerResponse</code> instances. The HTTP method, headers, and entity-body data will be sent. Which means that, if you don't really care about security, you can do:</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"http.createServer(function (req, resp) {\n if (req.url === '/doodle.png') {\n const x = request('http://mysite.com/doodle.png')\n req.pipe(x)\n x.pipe(resp)\n }\n})\"><pre><span class=\"pl-s1\">http</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">createServer</span><span class=\"pl-kos\">(</span><span class=\"pl-k\">function</span> <span class=\"pl-kos\">(</span><span class=\"pl-s1\">req</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">resp</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-k\">if</span> <span class=\"pl-kos\">(</span><span class=\"pl-s1\">req</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">url</span> <span class=\"pl-c1\">===</span> <span class=\"pl-s\">'/doodle.png'</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-k\">const</span> <span class=\"pl-s1\">x</span> <span class=\"pl-c1\">=</span> <span class=\"pl-en\">request</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://mysite.com/doodle.png'</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-s1\">req</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">pipe</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">x</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-s1\">x</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">pipe</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">resp</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">}</span>\n<span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span></pre></div>\n<p dir=\"auto\">And since <code>pipe()</code> returns the destination stream in ≥ Node 0.5.x you can do one line proxying. :)</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"req.pipe(request('http://mysite.com/doodle.png')).pipe(resp)\"><pre><span class=\"pl-s1\">req</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">pipe</span><span class=\"pl-kos\">(</span><span class=\"pl-en\">request</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://mysite.com/doodle.png'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">pipe</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">resp</span><span class=\"pl-kos\">)</span></pre></div>\n<p dir=\"auto\">Also, none of this new functionality conflicts with requests previous features, it just expands them.</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"const r = request.defaults({'proxy':'http://localproxy.com'})\n\nhttp.createServer(function (req, resp) {\n if (req.url === '/doodle.png') {\n r.get('http://google.com/doodle.png').pipe(resp)\n }\n})\"><pre><span class=\"pl-k\">const</span> <span class=\"pl-s1\">r</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">defaults</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">{</span><span class=\"pl-s\">'proxy'</span>:<span class=\"pl-s\">'http://localproxy.com'</span><span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span>\n\n<span class=\"pl-s1\">http</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">createServer</span><span class=\"pl-kos\">(</span><span class=\"pl-k\">function</span> <span class=\"pl-kos\">(</span><span class=\"pl-s1\">req</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">resp</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-k\">if</span> <span class=\"pl-kos\">(</span><span class=\"pl-s1\">req</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">url</span> <span class=\"pl-c1\">===</span> <span class=\"pl-s\">'/doodle.png'</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-s1\">r</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">get</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://google.com/doodle.png'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">pipe</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">resp</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">}</span>\n<span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span></pre></div>\n<p dir=\"auto\">You can still use intermediate proxies, the requests will still follow HTTP forwards, etc.</p>\n<p dir=\"auto\"><a href=\"#table-of-contents\">back to top</a></p>\n<hr>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">Promises &amp; Async/Await</h2><a id=\"user-content-promises--asyncawait\" class=\"anchor\" aria-label=\"Permalink: Promises &amp; Async/Await\" href=\"#promises--asyncawait\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\"><code>request</code> supports both streaming and callback interfaces natively. If you'd like <code>request</code> to return a Promise instead, you can use an alternative interface wrapper for <code>request</code>. These wrappers can be useful if you prefer to work with Promises, or if you'd like to use <code>async</code>/<code>await</code> in ES2017.</p>\n<p dir=\"auto\">Several alternative interfaces are provided by the request team, including:</p>\n<ul dir=\"auto\">\n<li><a href=\"https://github.com/request/request-promise\"><code>request-promise</code></a> (uses <a href=\"https://github.com/petkaantonov/bluebird\">Bluebird</a> Promises)</li>\n<li><a href=\"https://github.com/request/request-promise-native\"><code>request-promise-native</code></a> (uses native Promises)</li>\n<li><a href=\"https://github.com/request/request-promise-any\"><code>request-promise-any</code></a> (uses <a href=\"https://www.npmjs.com/package/any-promise\" rel=\"nofollow\">any-promise</a> Promises)</li>\n</ul>\n<p dir=\"auto\">Also, <a href=\"https://nodejs.org/api/util.html#util_util_promisify_original\" rel=\"nofollow\"><code>util.promisify</code></a>, which is available from Node.js v8.0 can be used to convert a regular function that takes a callback to return a promise instead.</p>\n<p dir=\"auto\"><a href=\"#table-of-contents\">back to top</a></p>\n<hr>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">Forms</h2><a id=\"user-content-forms\" class=\"anchor\" aria-label=\"Permalink: Forms\" href=\"#forms\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\"><code>request</code> supports <code>application/x-www-form-urlencoded</code> and <code>multipart/form-data</code> form uploads. For <code>multipart/related</code> refer to the <code>multipart</code> API.</p>\n<div class=\"markdown-heading\" dir=\"auto\"><h4 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">application/x-www-form-urlencoded (URL-Encoded Forms)</h4><a id=\"user-content-applicationx-www-form-urlencoded-url-encoded-forms\" class=\"anchor\" aria-label=\"Permalink: application/x-www-form-urlencoded (URL-Encoded Forms)\" href=\"#applicationx-www-form-urlencoded-url-encoded-forms\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">URL-encoded forms are simple.</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"request.post('http://service.com/upload', {form:{key:'value'}})\n// or\nrequest.post('http://service.com/upload').form({key:'value'})\n// or\nrequest.post({url:'http://service.com/upload', form: {key:'value'}}, function(err,httpResponse,body){ /* ... */ })\"><pre><span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">post</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://service.com/upload'</span><span class=\"pl-kos\">,</span> <span class=\"pl-kos\">{</span><span class=\"pl-c1\">form</span>:<span class=\"pl-kos\">{</span><span class=\"pl-c1\">key</span>:<span class=\"pl-s\">'value'</span><span class=\"pl-kos\">}</span><span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span>\n<span class=\"pl-c\">// or</span>\n<span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">post</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://service.com/upload'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">form</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">{</span><span class=\"pl-c1\">key</span>:<span class=\"pl-s\">'value'</span><span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span>\n<span class=\"pl-c\">// or</span>\n<span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">post</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">{</span><span class=\"pl-c1\">url</span>:<span class=\"pl-s\">'http://service.com/upload'</span><span class=\"pl-kos\">,</span> <span class=\"pl-c1\">form</span>: <span class=\"pl-kos\">{</span><span class=\"pl-c1\">key</span>:<span class=\"pl-s\">'value'</span><span class=\"pl-kos\">}</span><span class=\"pl-kos\">}</span><span class=\"pl-kos\">,</span> <span class=\"pl-k\">function</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">err</span><span class=\"pl-kos\">,</span><span class=\"pl-s1\">httpResponse</span><span class=\"pl-kos\">,</span><span class=\"pl-s1\">body</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">{</span> <span class=\"pl-c\">/* ... */</span> <span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span></pre></div>\n<div class=\"markdown-heading\" dir=\"auto\"><h4 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">multipart/form-data (Multipart Form Uploads)</h4><a id=\"user-content-multipartform-data-multipart-form-uploads\" class=\"anchor\" aria-label=\"Permalink: multipart/form-data (Multipart Form Uploads)\" href=\"#multipartform-data-multipart-form-uploads\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">For <code>multipart/form-data</code> we use the <a href=\"https://github.com/form-data/form-data\">form-data</a> library by <a href=\"https://github.com/felixge\">@felixge</a>. For the most cases, you can pass your upload form data via the <code>formData</code> option.</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"const formData = {\n // Pass a simple key-value pair\n my_field: 'my_value',\n // Pass data via Buffers\n my_buffer: Buffer.from([1, 2, 3]),\n // Pass data via Streams\n my_file: fs.createReadStream(__dirname + '/unicycle.jpg'),\n // Pass multiple values /w an Array\n attachments: [\n fs.createReadStream(__dirname + '/attachment1.jpg'),\n fs.createReadStream(__dirname + '/attachment2.jpg')\n ],\n // Pass optional meta-data with an 'options' object with style: {value: DATA, options: OPTIONS}\n // Use case: for some types of streams, you'll need to provide &quot;file&quot;-related information manually.\n // See the `form-data` README for more information about options: https://github.com/form-data/form-data\n custom_file: {\n value: fs.createReadStream('/dev/urandom'),\n options: {\n filename: 'topsecret.jpg',\n contentType: 'image/jpeg'\n }\n }\n};\nrequest.post({url:'http://service.com/upload', formData: formData}, function optionalCallback(err, httpResponse, body) {\n if (err) {\n return console.error('upload failed:', err);\n }\n console.log('Upload successful! Server responded with:', body);\n});\"><pre><span class=\"pl-k\">const</span> <span class=\"pl-s1\">formData</span> <span class=\"pl-c1\">=</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-c\">// Pass a simple key-value pair</span>\n <span class=\"pl-c1\">my_field</span>: <span class=\"pl-s\">'my_value'</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c\">// Pass data via Buffers</span>\n <span class=\"pl-c1\">my_buffer</span>: <span class=\"pl-v\">Buffer</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">from</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">[</span><span class=\"pl-c1\">1</span><span class=\"pl-kos\">,</span> <span class=\"pl-c1\">2</span><span class=\"pl-kos\">,</span> <span class=\"pl-c1\">3</span><span class=\"pl-kos\">]</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c\">// Pass data via Streams</span>\n <span class=\"pl-c1\">my_file</span>: <span class=\"pl-s1\">fs</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">createReadStream</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">__dirname</span> <span class=\"pl-c1\">+</span> <span class=\"pl-s\">'/unicycle.jpg'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c\">// Pass multiple values /w an Array</span>\n <span class=\"pl-c1\">attachments</span>: <span class=\"pl-kos\">[</span>\n <span class=\"pl-s1\">fs</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">createReadStream</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">__dirname</span> <span class=\"pl-c1\">+</span> <span class=\"pl-s\">'/attachment1.jpg'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-s1\">fs</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">createReadStream</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">__dirname</span> <span class=\"pl-c1\">+</span> <span class=\"pl-s\">'/attachment2.jpg'</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">]</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c\">// Pass optional meta-data with an 'options' object with style: {value: DATA, options: OPTIONS}</span>\n <span class=\"pl-c\">// Use case: for some types of streams, you'll need to provide \"file\"-related information manually.</span>\n <span class=\"pl-c\">// See the `form-data` README for more information about options: https://github.com/form-data/form-data</span>\n <span class=\"pl-c1\">custom_file</span>: <span class=\"pl-kos\">{</span>\n <span class=\"pl-c1\">value</span>: <span class=\"pl-s1\">fs</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">createReadStream</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'/dev/urandom'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">options</span>: <span class=\"pl-kos\">{</span>\n <span class=\"pl-c1\">filename</span>: <span class=\"pl-s\">'topsecret.jpg'</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">contentType</span>: <span class=\"pl-s\">'image/jpeg'</span>\n <span class=\"pl-kos\">}</span>\n <span class=\"pl-kos\">}</span>\n<span class=\"pl-kos\">}</span><span class=\"pl-kos\">;</span>\n<span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">post</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">{</span><span class=\"pl-c1\">url</span>:<span class=\"pl-s\">'http://service.com/upload'</span><span class=\"pl-kos\">,</span> <span class=\"pl-c1\">formData</span>: <span class=\"pl-s1\">formData</span><span class=\"pl-kos\">}</span><span class=\"pl-kos\">,</span> <span class=\"pl-k\">function</span> <span class=\"pl-en\">optionalCallback</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">err</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">httpResponse</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">body</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-k\">if</span> <span class=\"pl-kos\">(</span><span class=\"pl-s1\">err</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-k\">return</span> <span class=\"pl-smi\">console</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">error</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'upload failed:'</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">err</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span>\n <span class=\"pl-kos\">}</span>\n <span class=\"pl-smi\">console</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">log</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'Upload successful! Server responded with:'</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">body</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span>\n<span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span></pre></div>\n<p dir=\"auto\">For advanced cases, you can access the form-data object itself via <code>r.form()</code>. This can be modified until the request is fired on the next cycle of the event-loop. (Note that this calling <code>form()</code> will clear the currently set form data for that request.)</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"// NOTE: Advanced use-case, for normal use see 'formData' usage above\nconst r = request.post('http://service.com/upload', function optionalCallback(err, httpResponse, body) {...})\nconst form = r.form();\nform.append('my_field', 'my_value');\nform.append('my_buffer', Buffer.from([1, 2, 3]));\nform.append('custom_file', fs.createReadStream(__dirname + '/unicycle.jpg'), {filename: 'unicycle.jpg'});\"><pre><span class=\"pl-c\">// NOTE: Advanced use-case, for normal use see 'formData' usage above</span>\n<span class=\"pl-k\">const</span> <span class=\"pl-s1\">r</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">post</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://service.com/upload'</span><span class=\"pl-kos\">,</span> <span class=\"pl-k\">function</span> <span class=\"pl-en\">optionalCallback</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">err</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">httpResponse</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">body</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>...<span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span>\n<span class=\"pl-k\">const</span> <span class=\"pl-s1\">form</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s1\">r</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">form</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span>\n<span class=\"pl-s1\">form</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">append</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'my_field'</span><span class=\"pl-kos\">,</span> <span class=\"pl-s\">'my_value'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span>\n<span class=\"pl-s1\">form</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">append</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'my_buffer'</span><span class=\"pl-kos\">,</span> <span class=\"pl-v\">Buffer</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">from</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">[</span><span class=\"pl-c1\">1</span><span class=\"pl-kos\">,</span> <span class=\"pl-c1\">2</span><span class=\"pl-kos\">,</span> <span class=\"pl-c1\">3</span><span class=\"pl-kos\">]</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span>\n<span class=\"pl-s1\">form</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">append</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'custom_file'</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">fs</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">createReadStream</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">__dirname</span> <span class=\"pl-c1\">+</span> <span class=\"pl-s\">'/unicycle.jpg'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">,</span> <span class=\"pl-kos\">{</span><span class=\"pl-c1\">filename</span>: <span class=\"pl-s\">'unicycle.jpg'</span><span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span></pre></div>\n<p dir=\"auto\">See the <a href=\"https://github.com/form-data/form-data\">form-data README</a> for more information &amp; examples.</p>\n<div class=\"markdown-heading\" dir=\"auto\"><h4 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">multipart/related</h4><a id=\"user-content-multipartrelated\" class=\"anchor\" aria-label=\"Permalink: multipart/related\" href=\"#multipartrelated\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">Some variations in different HTTP implementations require a newline/CRLF before, after, or both before and after the boundary of a <code>multipart/related</code> request (using the multipart option). This has been observed in the .NET WebAPI version 4.0. You can turn on a boundary preambleCRLF or postamble by passing them as <code>true</code> to your request options.</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\" request({\n method: 'PUT',\n preambleCRLF: true,\n postambleCRLF: true,\n uri: 'http://service.com/upload',\n multipart: [\n {\n 'content-type': 'application/json',\n body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}})\n },\n { body: 'I am an attachment' },\n { body: fs.createReadStream('image.png') }\n ],\n // alternatively pass an object containing additional options\n multipart: {\n chunked: false,\n data: [\n {\n 'content-type': 'application/json',\n body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}})\n },\n { body: 'I am an attachment' }\n ]\n }\n },\n function (error, response, body) {\n if (error) {\n return console.error('upload failed:', error);\n }\n console.log('Upload successful! Server responded with:', body);\n })\"><pre> <span class=\"pl-en\">request</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">{</span>\n <span class=\"pl-c1\">method</span>: <span class=\"pl-s\">'PUT'</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">preambleCRLF</span>: <span class=\"pl-c1\">true</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">postambleCRLF</span>: <span class=\"pl-c1\">true</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">uri</span>: <span class=\"pl-s\">'http://service.com/upload'</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">multipart</span>: <span class=\"pl-kos\">[</span>\n <span class=\"pl-kos\">{</span>\n <span class=\"pl-s\">'content-type'</span>: <span class=\"pl-s\">'application/json'</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">body</span>: <span class=\"pl-c1\">JSON</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">stringify</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">{</span><span class=\"pl-c1\">foo</span>: <span class=\"pl-s\">'bar'</span><span class=\"pl-kos\">,</span> <span class=\"pl-c1\">_attachments</span>: <span class=\"pl-kos\">{</span><span class=\"pl-s\">'message.txt'</span>: <span class=\"pl-kos\">{</span><span class=\"pl-c1\">follows</span>: <span class=\"pl-c1\">true</span><span class=\"pl-kos\">,</span> <span class=\"pl-c1\">length</span>: <span class=\"pl-c1\">18</span><span class=\"pl-kos\">,</span> <span class=\"pl-s\">'content_type'</span>: <span class=\"pl-s\">'text/plain'</span> <span class=\"pl-kos\">}</span><span class=\"pl-kos\">}</span><span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">}</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-kos\">{</span> <span class=\"pl-c1\">body</span>: <span class=\"pl-s\">'I am an attachment'</span> <span class=\"pl-kos\">}</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-kos\">{</span> <span class=\"pl-c1\">body</span>: <span class=\"pl-s1\">fs</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">createReadStream</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'image.png'</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">}</span>\n <span class=\"pl-kos\">]</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c\">// alternatively pass an object containing additional options</span>\n <span class=\"pl-c1\">multipart</span>: <span class=\"pl-kos\">{</span>\n <span class=\"pl-c1\">chunked</span>: <span class=\"pl-c1\">false</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">data</span>: <span class=\"pl-kos\">[</span>\n <span class=\"pl-kos\">{</span>\n <span class=\"pl-s\">'content-type'</span>: <span class=\"pl-s\">'application/json'</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">body</span>: <span class=\"pl-c1\">JSON</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">stringify</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">{</span><span class=\"pl-c1\">foo</span>: <span class=\"pl-s\">'bar'</span><span class=\"pl-kos\">,</span> <span class=\"pl-c1\">_attachments</span>: <span class=\"pl-kos\">{</span><span class=\"pl-s\">'message.txt'</span>: <span class=\"pl-kos\">{</span><span class=\"pl-c1\">follows</span>: <span class=\"pl-c1\">true</span><span class=\"pl-kos\">,</span> <span class=\"pl-c1\">length</span>: <span class=\"pl-c1\">18</span><span class=\"pl-kos\">,</span> <span class=\"pl-s\">'content_type'</span>: <span class=\"pl-s\">'text/plain'</span> <span class=\"pl-kos\">}</span><span class=\"pl-kos\">}</span><span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">}</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-kos\">{</span> <span class=\"pl-c1\">body</span>: <span class=\"pl-s\">'I am an attachment'</span> <span class=\"pl-kos\">}</span>\n <span class=\"pl-kos\">]</span>\n <span class=\"pl-kos\">}</span>\n <span class=\"pl-kos\">}</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-k\">function</span> <span class=\"pl-kos\">(</span><span class=\"pl-s1\">error</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">response</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">body</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-k\">if</span> <span class=\"pl-kos\">(</span><span class=\"pl-s1\">error</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-k\">return</span> <span class=\"pl-smi\">console</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">error</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'upload failed:'</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">error</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span>\n <span class=\"pl-kos\">}</span>\n <span class=\"pl-smi\">console</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">log</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'Upload successful! Server responded with:'</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">body</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span>\n <span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span></pre></div>\n<p dir=\"auto\"><a href=\"#table-of-contents\">back to top</a></p>\n<hr>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">HTTP Authentication</h2><a id=\"user-content-http-authentication\" class=\"anchor\" aria-label=\"Permalink: HTTP Authentication\" href=\"#http-authentication\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"request.get('http://some.server.com/').auth('username', 'password', false);\n// or\nrequest.get('http://some.server.com/', {\n 'auth': {\n 'user': 'username',\n 'pass': 'password',\n 'sendImmediately': false\n }\n});\n// or\nrequest.get('http://some.server.com/').auth(null, null, true, 'bearerToken');\n// or\nrequest.get('http://some.server.com/', {\n 'auth': {\n 'bearer': 'bearerToken'\n }\n});\"><pre><span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">get</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://some.server.com/'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">auth</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'username'</span><span class=\"pl-kos\">,</span> <span class=\"pl-s\">'password'</span><span class=\"pl-kos\">,</span> <span class=\"pl-c1\">false</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span>\n<span class=\"pl-c\">// or</span>\n<span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">get</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://some.server.com/'</span><span class=\"pl-kos\">,</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-s\">'auth'</span>: <span class=\"pl-kos\">{</span>\n <span class=\"pl-s\">'user'</span>: <span class=\"pl-s\">'username'</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-s\">'pass'</span>: <span class=\"pl-s\">'password'</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-s\">'sendImmediately'</span>: <span class=\"pl-c1\">false</span>\n <span class=\"pl-kos\">}</span>\n<span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span>\n<span class=\"pl-c\">// or</span>\n<span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">get</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://some.server.com/'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">auth</span><span class=\"pl-kos\">(</span><span class=\"pl-c1\">null</span><span class=\"pl-kos\">,</span> <span class=\"pl-c1\">null</span><span class=\"pl-kos\">,</span> <span class=\"pl-c1\">true</span><span class=\"pl-kos\">,</span> <span class=\"pl-s\">'bearerToken'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span>\n<span class=\"pl-c\">// or</span>\n<span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">get</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://some.server.com/'</span><span class=\"pl-kos\">,</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-s\">'auth'</span>: <span class=\"pl-kos\">{</span>\n <span class=\"pl-s\">'bearer'</span>: <span class=\"pl-s\">'bearerToken'</span>\n <span class=\"pl-kos\">}</span>\n<span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span></pre></div>\n<p dir=\"auto\">If passed as an option, <code>auth</code> should be a hash containing values:</p>\n<ul dir=\"auto\">\n<li><code>user</code> || <code>username</code></li>\n<li><code>pass</code> || <code>password</code></li>\n<li><code>sendImmediately</code> (optional)</li>\n<li><code>bearer</code> (optional)</li>\n</ul>\n<p dir=\"auto\">The method form takes parameters\n<code>auth(username, password, sendImmediately, bearer)</code>.</p>\n<p dir=\"auto\"><code>sendImmediately</code> defaults to <code>true</code>, which causes a basic or bearer\nauthentication header to be sent. If <code>sendImmediately</code> is <code>false</code>, then\n<code>request</code> will retry with a proper authentication header after receiving a\n<code>401</code> response from the server (which must contain a <code>WWW-Authenticate</code> header\nindicating the required authentication method).</p>\n<p dir=\"auto\">Note that you can also specify basic authentication using the URL itself, as\ndetailed in <a href=\"http://www.ietf.org/rfc/rfc1738.txt\" rel=\"nofollow\">RFC 1738</a>. Simply pass the\n<code>user:password</code> before the host with an <code>@</code> sign:</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"const username = 'username',\n password = 'password',\n url = 'http://' + username + ':' + password + '@some.server.com';\n\nrequest({url}, function (error, response, body) {\n // Do more stuff with 'body' here\n});\"><pre><span class=\"pl-k\">const</span> <span class=\"pl-s1\">username</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s\">'username'</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-s1\">password</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s\">'password'</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-s1\">url</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s\">'http://'</span> <span class=\"pl-c1\">+</span> <span class=\"pl-s1\">username</span> <span class=\"pl-c1\">+</span> <span class=\"pl-s\">':'</span> <span class=\"pl-c1\">+</span> <span class=\"pl-s1\">password</span> <span class=\"pl-c1\">+</span> <span class=\"pl-s\">'@some.server.com'</span><span class=\"pl-kos\">;</span>\n\n<span class=\"pl-en\">request</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">{</span>url<span class=\"pl-kos\">}</span><span class=\"pl-kos\">,</span> <span class=\"pl-k\">function</span> <span class=\"pl-kos\">(</span><span class=\"pl-s1\">error</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">response</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">body</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-c\">// Do more stuff with 'body' here</span>\n<span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span></pre></div>\n<p dir=\"auto\">Digest authentication is supported, but it only works with <code>sendImmediately</code>\nset to <code>false</code>; otherwise <code>request</code> will send basic authentication on the\ninitial request, which will probably cause the request to fail.</p>\n<p dir=\"auto\">Bearer authentication is supported, and is activated when the <code>bearer</code> value is\navailable. The value may be either a <code>String</code> or a <code>Function</code> returning a\n<code>String</code>. Using a function to supply the bearer token is particularly useful if\nused in conjunction with <code>defaults</code> to allow a single function to supply the\nlast known token at the time of sending a request, or to compute one on the fly.</p>\n<p dir=\"auto\"><a href=\"#table-of-contents\">back to top</a></p>\n<hr>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">Custom HTTP Headers</h2><a id=\"user-content-custom-http-headers\" class=\"anchor\" aria-label=\"Permalink: Custom HTTP Headers\" href=\"#custom-http-headers\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">HTTP Headers, such as <code>User-Agent</code>, can be set in the <code>options</code> object.\nIn the example below, we call the github API to find out the number\nof stars and forks for the request repository. This requires a\ncustom <code>User-Agent</code> header as well as https.</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"const request = require('request');\n\nconst options = {\n url: 'https://api.github.com/repos/request/request',\n headers: {\n 'User-Agent': 'request'\n }\n};\n\nfunction callback(error, response, body) {\n if (!error &amp;&amp; response.statusCode == 200) {\n const info = JSON.parse(body);\n console.log(info.stargazers_count + &quot; Stars&quot;);\n console.log(info.forks_count + &quot; Forks&quot;);\n }\n}\n\nrequest(options, callback);\"><pre><span class=\"pl-k\">const</span> <span class=\"pl-s1\">request</span> <span class=\"pl-c1\">=</span> <span class=\"pl-en\">require</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'request'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span>\n\n<span class=\"pl-k\">const</span> <span class=\"pl-s1\">options</span> <span class=\"pl-c1\">=</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-c1\">url</span>: <span class=\"pl-s\">'https://api.github.com/repos/request/request'</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">headers</span>: <span class=\"pl-kos\">{</span>\n <span class=\"pl-s\">'User-Agent'</span>: <span class=\"pl-s\">'request'</span>\n <span class=\"pl-kos\">}</span>\n<span class=\"pl-kos\">}</span><span class=\"pl-kos\">;</span>\n\n<span class=\"pl-k\">function</span> <span class=\"pl-en\">callback</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">error</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">response</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">body</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-k\">if</span> <span class=\"pl-kos\">(</span><span class=\"pl-c1\">!</span><span class=\"pl-s1\">error</span> <span class=\"pl-c1\">&amp;&amp;</span> <span class=\"pl-s1\">response</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">statusCode</span> <span class=\"pl-c1\">==</span> <span class=\"pl-c1\">200</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-k\">const</span> <span class=\"pl-s1\">info</span> <span class=\"pl-c1\">=</span> <span class=\"pl-c1\">JSON</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">parse</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">body</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span>\n <span class=\"pl-smi\">console</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">log</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">info</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">stargazers_count</span> <span class=\"pl-c1\">+</span> <span class=\"pl-s\">\" Stars\"</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span>\n <span class=\"pl-smi\">console</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">log</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">info</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">forks_count</span> <span class=\"pl-c1\">+</span> <span class=\"pl-s\">\" Forks\"</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span>\n <span class=\"pl-kos\">}</span>\n<span class=\"pl-kos\">}</span>\n\n<span class=\"pl-s1\">request</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">options</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">callback</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span></pre></div>\n<p dir=\"auto\"><a href=\"#table-of-contents\">back to top</a></p>\n<hr>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">OAuth Signing</h2><a id=\"user-content-oauth-signing\" class=\"anchor\" aria-label=\"Permalink: OAuth Signing\" href=\"#oauth-signing\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\"><a href=\"https://tools.ietf.org/html/rfc5849\" rel=\"nofollow\">OAuth version 1.0</a> is supported. The\ndefault signing algorithm is\n<a href=\"https://tools.ietf.org/html/rfc5849#section-3.4.2\" rel=\"nofollow\">HMAC-SHA1</a>:</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"// OAuth1.0 - 3-legged server side flow (Twitter example)\n// step 1\nconst qs = require('querystring')\n , oauth =\n { callback: 'http://mysite.com/callback/'\n , consumer_key: CONSUMER_KEY\n , consumer_secret: CONSUMER_SECRET\n }\n , url = 'https://api.twitter.com/oauth/request_token'\n ;\nrequest.post({url:url, oauth:oauth}, function (e, r, body) {\n // Ideally, you would take the body in the response\n // and construct a URL that a user clicks on (like a sign in button).\n // The verifier is only available in the response after a user has\n // verified with twitter that they are authorizing your app.\n\n // step 2\n const req_data = qs.parse(body)\n const uri = 'https://api.twitter.com/oauth/authenticate'\n + '?' + qs.stringify({oauth_token: req_data.oauth_token})\n // redirect the user to the authorize uri\n\n // step 3\n // after the user is redirected back to your server\n const auth_data = qs.parse(body)\n , oauth =\n { consumer_key: CONSUMER_KEY\n , consumer_secret: CONSUMER_SECRET\n , token: auth_data.oauth_token\n , token_secret: req_data.oauth_token_secret\n , verifier: auth_data.oauth_verifier\n }\n , url = 'https://api.twitter.com/oauth/access_token'\n ;\n request.post({url:url, oauth:oauth}, function (e, r, body) {\n // ready to make signed requests on behalf of the user\n const perm_data = qs.parse(body)\n , oauth =\n { consumer_key: CONSUMER_KEY\n , consumer_secret: CONSUMER_SECRET\n , token: perm_data.oauth_token\n , token_secret: perm_data.oauth_token_secret\n }\n , url = 'https://api.twitter.com/1.1/users/show.json'\n , qs =\n { screen_name: perm_data.screen_name\n , user_id: perm_data.user_id\n }\n ;\n request.get({url:url, oauth:oauth, qs:qs, json:true}, function (e, r, user) {\n console.log(user)\n })\n })\n})\"><pre><span class=\"pl-c\">// OAuth1.0 - 3-legged server side flow (Twitter example)</span>\n<span class=\"pl-c\">// step 1</span>\n<span class=\"pl-k\">const</span> <span class=\"pl-s1\">qs</span> <span class=\"pl-c1\">=</span> <span class=\"pl-en\">require</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'querystring'</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-s1\">oauth</span> <span class=\"pl-c1\">=</span>\n <span class=\"pl-kos\">{</span> <span class=\"pl-c1\">callback</span>: <span class=\"pl-s\">'http://mysite.com/callback/'</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-c1\">consumer_key</span>: <span class=\"pl-c1\">CONSUMER_KEY</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-c1\">consumer_secret</span>: <span class=\"pl-c1\">CONSUMER_SECRET</span>\n <span class=\"pl-kos\">}</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-s1\">url</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s\">'https://api.twitter.com/oauth/request_token'</span>\n <span class=\"pl-kos\">;</span>\n<span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">post</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">{</span><span class=\"pl-c1\">url</span>:<span class=\"pl-s1\">url</span><span class=\"pl-kos\">,</span> <span class=\"pl-c1\">oauth</span>:<span class=\"pl-s1\">oauth</span><span class=\"pl-kos\">}</span><span class=\"pl-kos\">,</span> <span class=\"pl-k\">function</span> <span class=\"pl-kos\">(</span><span class=\"pl-s1\">e</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">r</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">body</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-c\">// Ideally, you would take the body in the response</span>\n <span class=\"pl-c\">// and construct a URL that a user clicks on (like a sign in button).</span>\n <span class=\"pl-c\">// The verifier is only available in the response after a user has</span>\n <span class=\"pl-c\">// verified with twitter that they are authorizing your app.</span>\n\n <span class=\"pl-c\">// step 2</span>\n <span class=\"pl-k\">const</span> <span class=\"pl-s1\">req_data</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s1\">qs</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">parse</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">body</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-k\">const</span> <span class=\"pl-s1\">uri</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s\">'https://api.twitter.com/oauth/authenticate'</span>\n <span class=\"pl-c1\">+</span> <span class=\"pl-s\">'?'</span> <span class=\"pl-c1\">+</span> <span class=\"pl-s1\">qs</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">stringify</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">{</span><span class=\"pl-c1\">oauth_token</span>: <span class=\"pl-s1\">req_data</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">oauth_token</span><span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-c\">// redirect the user to the authorize uri</span>\n\n <span class=\"pl-c\">// step 3</span>\n <span class=\"pl-c\">// after the user is redirected back to your server</span>\n <span class=\"pl-k\">const</span> <span class=\"pl-s1\">auth_data</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s1\">qs</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">parse</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">body</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-s1\">oauth</span> <span class=\"pl-c1\">=</span>\n <span class=\"pl-kos\">{</span> <span class=\"pl-c1\">consumer_key</span>: <span class=\"pl-c1\">CONSUMER_KEY</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-c1\">consumer_secret</span>: <span class=\"pl-c1\">CONSUMER_SECRET</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-c1\">token</span>: <span class=\"pl-s1\">auth_data</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">oauth_token</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-c1\">token_secret</span>: <span class=\"pl-s1\">req_data</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">oauth_token_secret</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-c1\">verifier</span>: <span class=\"pl-s1\">auth_data</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">oauth_verifier</span>\n <span class=\"pl-kos\">}</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-s1\">url</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s\">'https://api.twitter.com/oauth/access_token'</span>\n <span class=\"pl-kos\">;</span>\n <span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">post</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">{</span><span class=\"pl-c1\">url</span>:<span class=\"pl-s1\">url</span><span class=\"pl-kos\">,</span> <span class=\"pl-c1\">oauth</span>:<span class=\"pl-s1\">oauth</span><span class=\"pl-kos\">}</span><span class=\"pl-kos\">,</span> <span class=\"pl-k\">function</span> <span class=\"pl-kos\">(</span><span class=\"pl-s1\">e</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">r</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">body</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-c\">// ready to make signed requests on behalf of the user</span>\n <span class=\"pl-k\">const</span> <span class=\"pl-s1\">perm_data</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s1\">qs</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">parse</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">body</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-s1\">oauth</span> <span class=\"pl-c1\">=</span>\n <span class=\"pl-kos\">{</span> <span class=\"pl-c1\">consumer_key</span>: <span class=\"pl-c1\">CONSUMER_KEY</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-c1\">consumer_secret</span>: <span class=\"pl-c1\">CONSUMER_SECRET</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-c1\">token</span>: <span class=\"pl-s1\">perm_data</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">oauth_token</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-c1\">token_secret</span>: <span class=\"pl-s1\">perm_data</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">oauth_token_secret</span>\n <span class=\"pl-kos\">}</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-s1\">url</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s\">'https://api.twitter.com/1.1/users/show.json'</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-s1\">qs</span> <span class=\"pl-c1\">=</span>\n <span class=\"pl-kos\">{</span> <span class=\"pl-c1\">screen_name</span>: <span class=\"pl-s1\">perm_data</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">screen_name</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-c1\">user_id</span>: <span class=\"pl-s1\">perm_data</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">user_id</span>\n <span class=\"pl-kos\">}</span>\n <span class=\"pl-kos\">;</span>\n <span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">get</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">{</span><span class=\"pl-c1\">url</span>:<span class=\"pl-s1\">url</span><span class=\"pl-kos\">,</span> <span class=\"pl-c1\">oauth</span>:<span class=\"pl-s1\">oauth</span><span class=\"pl-kos\">,</span> <span class=\"pl-c1\">qs</span>:<span class=\"pl-s1\">qs</span><span class=\"pl-kos\">,</span> <span class=\"pl-c1\">json</span>:<span class=\"pl-c1\">true</span><span class=\"pl-kos\">}</span><span class=\"pl-kos\">,</span> <span class=\"pl-k\">function</span> <span class=\"pl-kos\">(</span><span class=\"pl-s1\">e</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">r</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">user</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-smi\">console</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">log</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">user</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span>\n<span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span></pre></div>\n<p dir=\"auto\">For <a href=\"https://tools.ietf.org/html/rfc5849#section-3.4.3\" rel=\"nofollow\">RSA-SHA1 signing</a>, make\nthe following changes to the OAuth options object:</p>\n<ul dir=\"auto\">\n<li>Pass <code>signature_method : 'RSA-SHA1'</code></li>\n<li>Instead of <code>consumer_secret</code>, specify a <code>private_key</code> string in\n<a href=\"http://how2ssl.com/articles/working_with_pem_files/\" rel=\"nofollow\">PEM format</a></li>\n</ul>\n<p dir=\"auto\">For <a href=\"http://oauth.net/core/1.0/#anchor22\" rel=\"nofollow\">PLAINTEXT signing</a>, make\nthe following changes to the OAuth options object:</p>\n<ul dir=\"auto\">\n<li>Pass <code>signature_method : 'PLAINTEXT'</code></li>\n</ul>\n<p dir=\"auto\">To send OAuth parameters via query params or in a post body as described in The\n<a href=\"http://oauth.net/core/1.0/#consumer_req_param\" rel=\"nofollow\">Consumer Request Parameters</a>\nsection of the oauth1 spec:</p>\n<ul dir=\"auto\">\n<li>Pass <code>transport_method : 'query'</code> or <code>transport_method : 'body'</code> in the OAuth\noptions object.</li>\n<li><code>transport_method</code> defaults to <code>'header'</code></li>\n</ul>\n<p dir=\"auto\">To use <a href=\"https://oauth.googlecode.com/svn/spec/ext/body_hash/1.0/oauth-bodyhash.html\" rel=\"nofollow\">Request Body Hash</a> you can either</p>\n<ul dir=\"auto\">\n<li>Manually generate the body hash and pass it as a string <code>body_hash: '...'</code></li>\n<li>Automatically generate the body hash by passing <code>body_hash: true</code></li>\n</ul>\n<p dir=\"auto\"><a href=\"#table-of-contents\">back to top</a></p>\n<hr>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">Proxies</h2><a id=\"user-content-proxies\" class=\"anchor\" aria-label=\"Permalink: Proxies\" href=\"#proxies\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">If you specify a <code>proxy</code> option, then the request (and any subsequent\nredirects) will be sent via a connection to the proxy server.</p>\n<p dir=\"auto\">If your endpoint is an <code>https</code> url, and you are using a proxy, then\nrequest will send a <code>CONNECT</code> request to the proxy server <em>first</em>, and\nthen use the supplied connection to connect to the endpoint.</p>\n<p dir=\"auto\">That is, first it will make a request like:</p>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"HTTP/1.1 CONNECT endpoint-server.com:80\nHost: proxy-server.com\nUser-Agent: whatever user agent you specify\"><pre class=\"notranslate\"><code>HTTP/1.1 CONNECT endpoint-server.com:80\nHost: proxy-server.com\nUser-Agent: whatever user agent you specify\n</code></pre></div>\n<p dir=\"auto\">and then the proxy server make a TCP connection to <code>endpoint-server</code>\non port <code>80</code>, and return a response that looks like:</p>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"HTTP/1.1 200 OK\"><pre class=\"notranslate\"><code>HTTP/1.1 200 OK\n</code></pre></div>\n<p dir=\"auto\">At this point, the connection is left open, and the client is\ncommunicating directly with the <code>endpoint-server.com</code> machine.</p>\n<p dir=\"auto\">See <a href=\"https://en.wikipedia.org/wiki/HTTP_tunnel\" rel=\"nofollow\">the wikipedia page on HTTP Tunneling</a>\nfor more information.</p>\n<p dir=\"auto\">By default, when proxying <code>http</code> traffic, request will simply make a\nstandard proxied <code>http</code> request. This is done by making the <code>url</code>\nsection of the initial line of the request a fully qualified url to\nthe endpoint.</p>\n<p dir=\"auto\">For example, it will make a single request that looks like:</p>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"HTTP/1.1 GET http://endpoint-server.com/some-url\nHost: proxy-server.com\nOther-Headers: all go here\n\nrequest body or whatever\"><pre class=\"notranslate\"><code>HTTP/1.1 GET http://endpoint-server.com/some-url\nHost: proxy-server.com\nOther-Headers: all go here\n\nrequest body or whatever\n</code></pre></div>\n<p dir=\"auto\">Because a pure \"http over http\" tunnel offers no additional security\nor other features, it is generally simpler to go with a\nstraightforward HTTP proxy in this case. However, if you would like\nto force a tunneling proxy, you may set the <code>tunnel</code> option to <code>true</code>.</p>\n<p dir=\"auto\">You can also make a standard proxied <code>http</code> request by explicitly setting\n<code>tunnel : false</code>, but <strong>note that this will allow the proxy to see the traffic\nto/from the destination server</strong>.</p>\n<p dir=\"auto\">If you are using a tunneling proxy, you may set the\n<code>proxyHeaderWhiteList</code> to share certain headers with the proxy.</p>\n<p dir=\"auto\">You can also set the <code>proxyHeaderExclusiveList</code> to share certain\nheaders only with the proxy and not with destination host.</p>\n<p dir=\"auto\">By default, this set is:</p>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"accept\naccept-charset\naccept-encoding\naccept-language\naccept-ranges\ncache-control\ncontent-encoding\ncontent-language\ncontent-length\ncontent-location\ncontent-md5\ncontent-range\ncontent-type\nconnection\ndate\nexpect\nmax-forwards\npragma\nproxy-authorization\nreferer\nte\ntransfer-encoding\nuser-agent\nvia\"><pre class=\"notranslate\"><code>accept\naccept-charset\naccept-encoding\naccept-language\naccept-ranges\ncache-control\ncontent-encoding\ncontent-language\ncontent-length\ncontent-location\ncontent-md5\ncontent-range\ncontent-type\nconnection\ndate\nexpect\nmax-forwards\npragma\nproxy-authorization\nreferer\nte\ntransfer-encoding\nuser-agent\nvia\n</code></pre></div>\n<p dir=\"auto\">Note that, when using a tunneling proxy, the <code>proxy-authorization</code>\nheader and any headers from custom <code>proxyHeaderExclusiveList</code> are\n<em>never</em> sent to the endpoint server, but only to the proxy server.</p>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">Controlling proxy behaviour using environment variables</h3><a id=\"user-content-controlling-proxy-behaviour-using-environment-variables\" class=\"anchor\" aria-label=\"Permalink: Controlling proxy behaviour using environment variables\" href=\"#controlling-proxy-behaviour-using-environment-variables\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">The following environment variables are respected by <code>request</code>:</p>\n<ul dir=\"auto\">\n<li><code>HTTP_PROXY</code> / <code>http_proxy</code></li>\n<li><code>HTTPS_PROXY</code> / <code>https_proxy</code></li>\n<li><code>NO_PROXY</code> / <code>no_proxy</code></li>\n</ul>\n<p dir=\"auto\">When <code>HTTP_PROXY</code> / <code>http_proxy</code> are set, they will be used to proxy non-SSL requests that do not have an explicit <code>proxy</code> configuration option present. Similarly, <code>HTTPS_PROXY</code> / <code>https_proxy</code> will be respected for SSL requests that do not have an explicit <code>proxy</code> configuration option. It is valid to define a proxy in one of the environment variables, but then override it for a specific request, using the <code>proxy</code> configuration option. Furthermore, the <code>proxy</code> configuration option can be explicitly set to false / null to opt out of proxying altogether for that request.</p>\n<p dir=\"auto\"><code>request</code> is also aware of the <code>NO_PROXY</code>/<code>no_proxy</code> environment variables. These variables provide a granular way to opt out of proxying, on a per-host basis. It should contain a comma separated list of hosts to opt out of proxying. It is also possible to opt of proxying when a particular destination port is used. Finally, the variable may be set to <code>*</code> to opt out of the implicit proxy configuration of the other environment variables.</p>\n<p dir=\"auto\">Here's some examples of valid <code>no_proxy</code> values:</p>\n<ul dir=\"auto\">\n<li><code>google.com</code> - don't proxy HTTP/HTTPS requests to Google.</li>\n<li><code>google.com:443</code> - don't proxy HTTPS requests to Google, but <em>do</em> proxy HTTP requests to Google.</li>\n<li><code>google.com:443, yahoo.com:80</code> - don't proxy HTTPS requests to Google, and don't proxy HTTP requests to Yahoo!</li>\n<li><code>*</code> - ignore <code>https_proxy</code>/<code>http_proxy</code> environment variables altogether.</li>\n</ul>\n<p dir=\"auto\"><a href=\"#table-of-contents\">back to top</a></p>\n<hr>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">UNIX Domain Sockets</h2><a id=\"user-content-unix-domain-sockets\" class=\"anchor\" aria-label=\"Permalink: UNIX Domain Sockets\" href=\"#unix-domain-sockets\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\"><code>request</code> supports making requests to <a href=\"https://en.wikipedia.org/wiki/Unix_domain_socket\" rel=\"nofollow\">UNIX Domain Sockets</a>. To make one, use the following URL scheme:</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"/* Pattern */ 'http://unix:SOCKET:PATH'\n/* Example */ request.get('http://unix:/absolute/path/to/unix.socket:/request/path')\"><pre><span class=\"pl-c\">/* Pattern */</span> <span class=\"pl-s\">'http://unix:SOCKET:PATH'</span>\n<span class=\"pl-c\">/* Example */</span> <span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">get</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://unix:/absolute/path/to/unix.socket:/request/path'</span><span class=\"pl-kos\">)</span></pre></div>\n<p dir=\"auto\">Note: The <code>SOCKET</code> path is assumed to be absolute to the root of the host file system.</p>\n<p dir=\"auto\"><a href=\"#table-of-contents\">back to top</a></p>\n<hr>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">TLS/SSL Protocol</h2><a id=\"user-content-tlsssl-protocol\" class=\"anchor\" aria-label=\"Permalink: TLS/SSL Protocol\" href=\"#tlsssl-protocol\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">TLS/SSL Protocol options, such as <code>cert</code>, <code>key</code> and <code>passphrase</code>, can be\nset directly in <code>options</code> object, in the <code>agentOptions</code> property of the <code>options</code> object, or even in <code>https.globalAgent.options</code>. Keep in mind that, although <code>agentOptions</code> allows for a slightly wider range of configurations, the recommended way is via <code>options</code> object directly, as using <code>agentOptions</code> or <code>https.globalAgent.options</code> would not be applied in the same way in proxied environments (as data travels through a TLS connection instead of an http/https agent).</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"const fs = require('fs')\n , path = require('path')\n , certFile = path.resolve(__dirname, 'ssl/client.crt')\n , keyFile = path.resolve(__dirname, 'ssl/client.key')\n , caFile = path.resolve(__dirname, 'ssl/ca.cert.pem')\n , request = require('request');\n\nconst options = {\n url: 'https://api.some-server.com/',\n cert: fs.readFileSync(certFile),\n key: fs.readFileSync(keyFile),\n passphrase: 'password',\n ca: fs.readFileSync(caFile)\n};\n\nrequest.get(options);\"><pre><span class=\"pl-k\">const</span> <span class=\"pl-s1\">fs</span> <span class=\"pl-c1\">=</span> <span class=\"pl-en\">require</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'fs'</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-s1\">path</span> <span class=\"pl-c1\">=</span> <span class=\"pl-en\">require</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'path'</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-s1\">certFile</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s1\">path</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">resolve</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">__dirname</span><span class=\"pl-kos\">,</span> <span class=\"pl-s\">'ssl/client.crt'</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-s1\">keyFile</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s1\">path</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">resolve</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">__dirname</span><span class=\"pl-kos\">,</span> <span class=\"pl-s\">'ssl/client.key'</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-s1\">caFile</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s1\">path</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">resolve</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">__dirname</span><span class=\"pl-kos\">,</span> <span class=\"pl-s\">'ssl/ca.cert.pem'</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-s1\">request</span> <span class=\"pl-c1\">=</span> <span class=\"pl-en\">require</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'request'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span>\n\n<span class=\"pl-k\">const</span> <span class=\"pl-s1\">options</span> <span class=\"pl-c1\">=</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-c1\">url</span>: <span class=\"pl-s\">'https://api.some-server.com/'</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">cert</span>: <span class=\"pl-s1\">fs</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">readFileSync</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">certFile</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">key</span>: <span class=\"pl-s1\">fs</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">readFileSync</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">keyFile</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">passphrase</span>: <span class=\"pl-s\">'password'</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">ca</span>: <span class=\"pl-s1\">fs</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">readFileSync</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">caFile</span><span class=\"pl-kos\">)</span>\n<span class=\"pl-kos\">}</span><span class=\"pl-kos\">;</span>\n\n<span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">get</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">options</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span></pre></div>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">Using <code>options.agentOptions</code></h3><a id=\"user-content-using-optionsagentoptions\" class=\"anchor\" aria-label=\"Permalink: Using options.agentOptions\" href=\"#using-optionsagentoptions\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">In the example below, we call an API that requires client side SSL certificate\n(in PEM format) with passphrase protected private key (in PEM format) and disable the SSLv3 protocol:</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"const fs = require('fs')\n , path = require('path')\n , certFile = path.resolve(__dirname, 'ssl/client.crt')\n , keyFile = path.resolve(__dirname, 'ssl/client.key')\n , request = require('request');\n\nconst options = {\n url: 'https://api.some-server.com/',\n agentOptions: {\n cert: fs.readFileSync(certFile),\n key: fs.readFileSync(keyFile),\n // Or use `pfx` property replacing `cert` and `key` when using private key, certificate and CA certs in PFX or PKCS12 format:\n // pfx: fs.readFileSync(pfxFilePath),\n passphrase: 'password',\n securityOptions: 'SSL_OP_NO_SSLv3'\n }\n};\n\nrequest.get(options);\"><pre><span class=\"pl-k\">const</span> <span class=\"pl-s1\">fs</span> <span class=\"pl-c1\">=</span> <span class=\"pl-en\">require</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'fs'</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-s1\">path</span> <span class=\"pl-c1\">=</span> <span class=\"pl-en\">require</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'path'</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-s1\">certFile</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s1\">path</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">resolve</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">__dirname</span><span class=\"pl-kos\">,</span> <span class=\"pl-s\">'ssl/client.crt'</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-s1\">keyFile</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s1\">path</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">resolve</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">__dirname</span><span class=\"pl-kos\">,</span> <span class=\"pl-s\">'ssl/client.key'</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-s1\">request</span> <span class=\"pl-c1\">=</span> <span class=\"pl-en\">require</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'request'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span>\n\n<span class=\"pl-k\">const</span> <span class=\"pl-s1\">options</span> <span class=\"pl-c1\">=</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-c1\">url</span>: <span class=\"pl-s\">'https://api.some-server.com/'</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">agentOptions</span>: <span class=\"pl-kos\">{</span>\n <span class=\"pl-c1\">cert</span>: <span class=\"pl-s1\">fs</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">readFileSync</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">certFile</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">key</span>: <span class=\"pl-s1\">fs</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">readFileSync</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">keyFile</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c\">// Or use `pfx` property replacing `cert` and `key` when using private key, certificate and CA certs in PFX or PKCS12 format:</span>\n <span class=\"pl-c\">// pfx: fs.readFileSync(pfxFilePath),</span>\n <span class=\"pl-c1\">passphrase</span>: <span class=\"pl-s\">'password'</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">securityOptions</span>: <span class=\"pl-s\">'SSL_OP_NO_SSLv3'</span>\n <span class=\"pl-kos\">}</span>\n<span class=\"pl-kos\">}</span><span class=\"pl-kos\">;</span>\n\n<span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">get</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">options</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span></pre></div>\n<p dir=\"auto\">It is able to force using SSLv3 only by specifying <code>secureProtocol</code>:</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"request.get({\n url: 'https://api.some-server.com/',\n agentOptions: {\n secureProtocol: 'SSLv3_method'\n }\n});\"><pre><span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">get</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">{</span>\n <span class=\"pl-c1\">url</span>: <span class=\"pl-s\">'https://api.some-server.com/'</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">agentOptions</span>: <span class=\"pl-kos\">{</span>\n <span class=\"pl-c1\">secureProtocol</span>: <span class=\"pl-s\">'SSLv3_method'</span>\n <span class=\"pl-kos\">}</span>\n<span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span></pre></div>\n<p dir=\"auto\">It is possible to accept other certificates than those signed by generally allowed Certificate Authorities (CAs).\nThis can be useful, for example, when using self-signed certificates.\nTo require a different root certificate, you can specify the signing CA by adding the contents of the CA's certificate file to the <code>agentOptions</code>.\nThe certificate the domain presents must be signed by the root certificate specified:</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"request.get({\n url: 'https://api.some-server.com/',\n agentOptions: {\n ca: fs.readFileSync('ca.cert.pem')\n }\n});\"><pre><span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">get</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">{</span>\n <span class=\"pl-c1\">url</span>: <span class=\"pl-s\">'https://api.some-server.com/'</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">agentOptions</span>: <span class=\"pl-kos\">{</span>\n <span class=\"pl-c1\">ca</span>: <span class=\"pl-s1\">fs</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">readFileSync</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'ca.cert.pem'</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">}</span>\n<span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span></pre></div>\n<p dir=\"auto\">The <code>ca</code> value can be an array of certificates, in the event you have a private or internal corporate public-key infrastructure hierarchy. For example, if you want to connect to <a href=\"https://api.some-server.com\" rel=\"nofollow\">https://api.some-server.com</a> which presents a key chain consisting of:</p>\n<ol dir=\"auto\">\n<li>its own public key, which is signed by:</li>\n<li>an intermediate \"Corp Issuing Server\", that is in turn signed by:</li>\n<li>a root CA \"Corp Root CA\";</li>\n</ol>\n<p dir=\"auto\">you can configure your request as follows:</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"request.get({\n url: 'https://api.some-server.com/',\n agentOptions: {\n ca: [\n fs.readFileSync('Corp Issuing Server.pem'),\n fs.readFileSync('Corp Root CA.pem')\n ]\n }\n});\"><pre><span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">get</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">{</span>\n <span class=\"pl-c1\">url</span>: <span class=\"pl-s\">'https://api.some-server.com/'</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">agentOptions</span>: <span class=\"pl-kos\">{</span>\n <span class=\"pl-c1\">ca</span>: <span class=\"pl-kos\">[</span>\n <span class=\"pl-s1\">fs</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">readFileSync</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'Corp Issuing Server.pem'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-s1\">fs</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">readFileSync</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'Corp Root CA.pem'</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">]</span>\n <span class=\"pl-kos\">}</span>\n<span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span></pre></div>\n<p dir=\"auto\"><a href=\"#table-of-contents\">back to top</a></p>\n<hr>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">Support for HAR 1.2</h2><a id=\"user-content-support-for-har-12\" class=\"anchor\" aria-label=\"Permalink: Support for HAR 1.2\" href=\"#support-for-har-12\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">The <code>options.har</code> property will override the values: <code>url</code>, <code>method</code>, <code>qs</code>, <code>headers</code>, <code>form</code>, <code>formData</code>, <code>body</code>, <code>json</code>, as well as construct multipart data and read files from disk when <code>request.postData.params[].fileName</code> is present without a matching <code>value</code>.</p>\n<p dir=\"auto\">A validation step will check if the HAR Request format matches the latest spec (v1.2) and will skip parsing if not matching.</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\" const request = require('request')\n request({\n // will be ignored\n method: 'GET',\n uri: 'http://www.google.com',\n\n // HTTP Archive Request Object\n har: {\n url: 'http://www.mockbin.com/har',\n method: 'POST',\n headers: [\n {\n name: 'content-type',\n value: 'application/x-www-form-urlencoded'\n }\n ],\n postData: {\n mimeType: 'application/x-www-form-urlencoded',\n params: [\n {\n name: 'foo',\n value: 'bar'\n },\n {\n name: 'hello',\n value: 'world'\n }\n ]\n }\n }\n })\n\n // a POST request will be sent to http://www.mockbin.com\n // with body an application/x-www-form-urlencoded body:\n // foo=bar&amp;hello=world\"><pre> <span class=\"pl-k\">const</span> <span class=\"pl-s1\">request</span> <span class=\"pl-c1\">=</span> <span class=\"pl-en\">require</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'request'</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-s1\">request</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">{</span>\n <span class=\"pl-c\">// will be ignored</span>\n <span class=\"pl-c1\">method</span>: <span class=\"pl-s\">'GET'</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">uri</span>: <span class=\"pl-s\">'http://www.google.com'</span><span class=\"pl-kos\">,</span>\n\n <span class=\"pl-c\">// HTTP Archive Request Object</span>\n <span class=\"pl-c1\">har</span>: <span class=\"pl-kos\">{</span>\n <span class=\"pl-c1\">url</span>: <span class=\"pl-s\">'http://www.mockbin.com/har'</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">method</span>: <span class=\"pl-s\">'POST'</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">headers</span>: <span class=\"pl-kos\">[</span>\n <span class=\"pl-kos\">{</span>\n <span class=\"pl-c1\">name</span>: <span class=\"pl-s\">'content-type'</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">value</span>: <span class=\"pl-s\">'application/x-www-form-urlencoded'</span>\n <span class=\"pl-kos\">}</span>\n <span class=\"pl-kos\">]</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">postData</span>: <span class=\"pl-kos\">{</span>\n <span class=\"pl-c1\">mimeType</span>: <span class=\"pl-s\">'application/x-www-form-urlencoded'</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">params</span>: <span class=\"pl-kos\">[</span>\n <span class=\"pl-kos\">{</span>\n <span class=\"pl-c1\">name</span>: <span class=\"pl-s\">'foo'</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">value</span>: <span class=\"pl-s\">'bar'</span>\n <span class=\"pl-kos\">}</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-kos\">{</span>\n <span class=\"pl-c1\">name</span>: <span class=\"pl-s\">'hello'</span><span class=\"pl-kos\">,</span>\n <span class=\"pl-c1\">value</span>: <span class=\"pl-s\">'world'</span>\n <span class=\"pl-kos\">}</span>\n <span class=\"pl-kos\">]</span>\n <span class=\"pl-kos\">}</span>\n <span class=\"pl-kos\">}</span>\n <span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span>\n\n <span class=\"pl-c\">// a POST request will be sent to http://www.mockbin.com</span>\n <span class=\"pl-c\">// with body an application/x-www-form-urlencoded body:</span>\n <span class=\"pl-c\">// foo=bar&amp;hello=world</span></pre></div>\n<p dir=\"auto\"><a href=\"#table-of-contents\">back to top</a></p>\n<hr>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">request(options, callback)</h2><a id=\"user-content-requestoptions-callback\" class=\"anchor\" aria-label=\"Permalink: request(options, callback)\" href=\"#requestoptions-callback\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">The first argument can be either a <code>url</code> or an <code>options</code> object. The only required option is <code>uri</code>; all others are optional.</p>\n<ul dir=\"auto\">\n<li><code>uri</code> || <code>url</code> - fully qualified uri or a parsed url object from <code>url.parse()</code></li>\n<li><code>baseUrl</code> - fully qualified uri string used as the base url. Most useful with <code>request.defaults</code>, for example when you want to do many requests to the same domain. If <code>baseUrl</code> is <code>https://example.com/api/</code>, then requesting <code>/end/point?test=true</code> will fetch <code>https://example.com/api/end/point?test=true</code>. When <code>baseUrl</code> is given, <code>uri</code> must also be a string.</li>\n<li><code>method</code> - http method (default: <code>\"GET\"</code>)</li>\n<li><code>headers</code> - http headers (default: <code>{}</code>)</li>\n</ul>\n<hr>\n<ul dir=\"auto\">\n<li><code>qs</code> - object containing querystring values to be appended to the <code>uri</code></li>\n<li><code>qsParseOptions</code> - object containing options to pass to the <a href=\"https://github.com/hapijs/qs#parsing-objects\">qs.parse</a> method. Alternatively pass options to the <a href=\"https://nodejs.org/docs/v0.12.0/api/querystring.html#querystring_querystring_parse_str_sep_eq_options\" rel=\"nofollow\">querystring.parse</a> method using this format <code>{sep:';', eq:':', options:{}}</code></li>\n<li><code>qsStringifyOptions</code> - object containing options to pass to the <a href=\"https://github.com/hapijs/qs#stringifying\">qs.stringify</a> method. Alternatively pass options to the <a href=\"https://nodejs.org/docs/v0.12.0/api/querystring.html#querystring_querystring_stringify_obj_sep_eq_options\" rel=\"nofollow\">querystring.stringify</a> method using this format <code>{sep:';', eq:':', options:{}}</code>. For example, to change the way arrays are converted to query strings using the <code>qs</code> module pass the <code>arrayFormat</code> option with one of <code>indices|brackets|repeat</code></li>\n<li><code>useQuerystring</code> - if true, use <code>querystring</code> to stringify and parse\nquerystrings, otherwise use <code>qs</code> (default: <code>false</code>). Set this option to\n<code>true</code> if you need arrays to be serialized as <code>foo=bar&amp;foo=baz</code> instead of the\ndefault <code>foo[0]=bar&amp;foo[1]=baz</code>.</li>\n</ul>\n<hr>\n<ul dir=\"auto\">\n<li><code>body</code> - entity body for PATCH, POST and PUT requests. Must be a <code>Buffer</code>, <code>String</code> or <code>ReadStream</code>. If <code>json</code> is <code>true</code>, then <code>body</code> must be a JSON-serializable object.</li>\n<li><code>form</code> - when passed an object or a querystring, this sets <code>body</code> to a querystring representation of value, and adds <code>Content-type: application/x-www-form-urlencoded</code> header. When passed no options, a <code>FormData</code> instance is returned (and is piped to request). See \"Forms\" section above.</li>\n<li><code>formData</code> - data to pass for a <code>multipart/form-data</code> request. See\n<a href=\"#forms\">Forms</a> section above.</li>\n<li><code>multipart</code> - array of objects which contain their own headers and <code>body</code>\nattributes. Sends a <code>multipart/related</code> request. See <a href=\"#forms\">Forms</a> section\nabove.\n<ul dir=\"auto\">\n<li>Alternatively you can pass in an object <code>{chunked: false, data: []}</code> where\n<code>chunked</code> is used to specify whether the request is sent in\n<a href=\"https://en.wikipedia.org/wiki/Chunked_transfer_encoding\" rel=\"nofollow\">chunked transfer encoding</a>\nIn non-chunked requests, data items with body streams are not allowed.</li>\n</ul>\n</li>\n<li><code>preambleCRLF</code> - append a newline/CRLF before the boundary of your <code>multipart/form-data</code> request.</li>\n<li><code>postambleCRLF</code> - append a newline/CRLF at the end of the boundary of your <code>multipart/form-data</code> request.</li>\n<li><code>json</code> - sets <code>body</code> to JSON representation of value and adds <code>Content-type: application/json</code> header. Additionally, parses the response body as JSON.</li>\n<li><code>jsonReviver</code> - a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse\" rel=\"nofollow\">reviver function</a> that will be passed to <code>JSON.parse()</code> when parsing a JSON response body.</li>\n<li><code>jsonReplacer</code> - a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify\" rel=\"nofollow\">replacer function</a> that will be passed to <code>JSON.stringify()</code> when stringifying a JSON request body.</li>\n</ul>\n<hr>\n<ul dir=\"auto\">\n<li><code>auth</code> - a hash containing values <code>user</code> || <code>username</code>, <code>pass</code> || <code>password</code>, and <code>sendImmediately</code> (optional). See documentation above.</li>\n<li><code>oauth</code> - options for OAuth HMAC-SHA1 signing. See documentation above.</li>\n<li><code>hawk</code> - options for <a href=\"https://github.com/hueniverse/hawk\">Hawk signing</a>. The <code>credentials</code> key must contain the necessary signing info, <a href=\"https://github.com/hueniverse/hawk#usage-example\">see hawk docs for details</a>.</li>\n<li><code>aws</code> - <code>object</code> containing AWS signing information. Should have the properties <code>key</code>, <code>secret</code>, and optionally <code>session</code> (note that this only works for services that require session as part of the canonical string). Also requires the property <code>bucket</code>, unless you’re specifying your <code>bucket</code> as part of the path, or the request doesn’t use a bucket (i.e. GET Services). If you want to use AWS sign version 4 use the parameter <code>sign_version</code> with value <code>4</code> otherwise the default is version 2. If you are using SigV4, you can also include a <code>service</code> property that specifies the service name. <strong>Note:</strong> you need to <code>npm install aws4</code> first.</li>\n<li><code>httpSignature</code> - options for the <a href=\"https://github.com/joyent/node-http-signature/blob/master/http_signing.md\">HTTP Signature Scheme</a> using <a href=\"https://github.com/joyent/node-http-signature\">Joyent's library</a>. The <code>keyId</code> and <code>key</code> properties must be specified. See the docs for other options.</li>\n</ul>\n<hr>\n<ul dir=\"auto\">\n<li><code>followRedirect</code> - follow HTTP 3xx responses as redirects (default: <code>true</code>). This property can also be implemented as function which gets <code>response</code> object as a single argument and should return <code>true</code> if redirects should continue or <code>false</code> otherwise.</li>\n<li><code>followAllRedirects</code> - follow non-GET HTTP 3xx responses as redirects (default: <code>false</code>)</li>\n<li><code>followOriginalHttpMethod</code> - by default we redirect to HTTP method GET. you can enable this property to redirect to the original HTTP method (default: <code>false</code>)</li>\n<li><code>maxRedirects</code> - the maximum number of redirects to follow (default: <code>10</code>)</li>\n<li><code>removeRefererHeader</code> - removes the referer header when a redirect happens (default: <code>false</code>). <strong>Note:</strong> if true, referer header set in the initial request is preserved during redirect chain.</li>\n</ul>\n<hr>\n<ul dir=\"auto\">\n<li><code>encoding</code> - encoding to be used on <code>setEncoding</code> of response data. If <code>null</code>, the <code>body</code> is returned as a <code>Buffer</code>. Anything else <strong>(including the default value of <code>undefined</code>)</strong> will be passed as the <a href=\"http://nodejs.org/api/buffer.html#buffer_buffer\" rel=\"nofollow\">encoding</a> parameter to <code>toString()</code> (meaning this is effectively <code>utf8</code> by default). (<strong>Note:</strong> if you expect binary data, you should set <code>encoding: null</code>.)</li>\n<li><code>gzip</code> - if <code>true</code>, add an <code>Accept-Encoding</code> header to request compressed content encodings from the server (if not already present) and decode supported content encodings in the response. <strong>Note:</strong> Automatic decoding of the response content is performed on the body data returned through <code>request</code> (both through the <code>request</code> stream and passed to the callback function) but is not performed on the <code>response</code> stream (available from the <code>response</code> event) which is the unmodified <code>http.IncomingMessage</code> object which may contain compressed data. See example below.</li>\n<li><code>jar</code> - if <code>true</code>, remember cookies for future use (or define your custom cookie jar; see examples section)</li>\n</ul>\n<hr>\n<ul dir=\"auto\">\n<li><code>agent</code> - <code>http(s).Agent</code> instance to use</li>\n<li><code>agentClass</code> - alternatively specify your agent's class name</li>\n<li><code>agentOptions</code> - and pass its options. <strong>Note:</strong> for HTTPS see <a href=\"http://nodejs.org/api/tls.html#tls_tls_connect_options_callback\" rel=\"nofollow\">tls API doc for TLS/SSL options</a> and the <a href=\"#using-optionsagentoptions\">documentation above</a>.</li>\n<li><code>forever</code> - set to <code>true</code> to use the <a href=\"https://github.com/request/forever-agent\">forever-agent</a> <strong>Note:</strong> Defaults to <code>http(s).Agent({keepAlive:true})</code> in node 0.12+</li>\n<li><code>pool</code> - an object describing which agents to use for the request. If this option is omitted the request will use the global agent (as long as your options allow for it). Otherwise, request will search the pool for your custom agent. If no custom agent is found, a new agent will be created and added to the pool. <strong>Note:</strong> <code>pool</code> is used only when the <code>agent</code> option is not specified.\n<ul dir=\"auto\">\n<li>A <code>maxSockets</code> property can also be provided on the <code>pool</code> object to set the max number of sockets for all agents created (ex: <code>pool: {maxSockets: Infinity}</code>).</li>\n<li>Note that if you are sending multiple requests in a loop and creating\nmultiple new <code>pool</code> objects, <code>maxSockets</code> will not work as intended. To\nwork around this, either use <a href=\"#requestdefaultsoptions\"><code>request.defaults</code></a>\nwith your pool options or create the pool object with the <code>maxSockets</code>\nproperty outside of the loop.</li>\n</ul>\n</li>\n<li><code>timeout</code> - integer containing number of milliseconds, controls two timeouts.\n<ul dir=\"auto\">\n<li><strong>Read timeout</strong>: Time to wait for a server to send response headers (and start the response body) before aborting the request.</li>\n<li><strong>Connection timeout</strong>: Sets the socket to timeout after <code>timeout</code> milliseconds of inactivity. Note that increasing the timeout beyond the OS-wide TCP connection timeout will not have any effect (<a href=\"http://www.sekuda.com/overriding_the_default_linux_kernel_20_second_tcp_socket_connect_timeout\" rel=\"nofollow\">the default in Linux can be anywhere from 20-120 seconds</a>)</li>\n</ul>\n</li>\n</ul>\n<hr>\n<ul dir=\"auto\">\n<li><code>localAddress</code> - local interface to bind for network connections.</li>\n<li><code>proxy</code> - an HTTP proxy to be used. Supports proxy Auth with Basic Auth, identical to support for the <code>url</code> parameter (by embedding the auth info in the <code>uri</code>)</li>\n<li><code>strictSSL</code> - if <code>true</code>, requires SSL certificates be valid. <strong>Note:</strong> to use your own certificate authority, you need to specify an agent that was created with that CA as an option.</li>\n<li><code>tunnel</code> - controls the behavior of\n<a href=\"https://en.wikipedia.org/wiki/HTTP_tunnel#HTTP_CONNECT_tunneling\" rel=\"nofollow\">HTTP <code>CONNECT</code> tunneling</a>\nas follows:\n<ul dir=\"auto\">\n<li><code>undefined</code> (default) - <code>true</code> if the destination is <code>https</code>, <code>false</code> otherwise</li>\n<li><code>true</code> - always tunnel to the destination by making a <code>CONNECT</code> request to\nthe proxy</li>\n<li><code>false</code> - request the destination as a <code>GET</code> request.</li>\n</ul>\n</li>\n<li><code>proxyHeaderWhiteList</code> - a whitelist of headers to send to a\ntunneling proxy.</li>\n<li><code>proxyHeaderExclusiveList</code> - a whitelist of headers to send\nexclusively to a tunneling proxy and not to destination.</li>\n</ul>\n<hr>\n<ul dir=\"auto\">\n<li>\n<p dir=\"auto\"><code>time</code> - if <code>true</code>, the request-response cycle (including all redirects) is timed at millisecond resolution. When set, the following properties are added to the response object:</p>\n<ul dir=\"auto\">\n<li><code>elapsedTime</code> Duration of the entire request/response in milliseconds (<em>deprecated</em>).</li>\n<li><code>responseStartTime</code> Timestamp when the response began (in Unix Epoch milliseconds) (<em>deprecated</em>).</li>\n<li><code>timingStart</code> Timestamp of the start of the request (in Unix Epoch milliseconds).</li>\n<li><code>timings</code> Contains event timestamps in millisecond resolution relative to <code>timingStart</code>. If there were redirects, the properties reflect the timings of the final request in the redirect chain:\n<ul dir=\"auto\">\n<li><code>socket</code> Relative timestamp when the <a href=\"https://nodejs.org/api/http.html#http_event_socket\" rel=\"nofollow\"><code>http</code></a> module's <code>socket</code> event fires. This happens when the socket is assigned to the request.</li>\n<li><code>lookup</code> Relative timestamp when the <a href=\"https://nodejs.org/api/net.html#net_event_lookup\" rel=\"nofollow\"><code>net</code></a> module's <code>lookup</code> event fires. This happens when the DNS has been resolved.</li>\n<li><code>connect</code>: Relative timestamp when the <a href=\"https://nodejs.org/api/net.html#net_event_connect\" rel=\"nofollow\"><code>net</code></a> module's <code>connect</code> event fires. This happens when the server acknowledges the TCP connection.</li>\n<li><code>response</code>: Relative timestamp when the <a href=\"https://nodejs.org/api/http.html#http_event_response\" rel=\"nofollow\"><code>http</code></a> module's <code>response</code> event fires. This happens when the first bytes are received from the server.</li>\n<li><code>end</code>: Relative timestamp when the last bytes of the response are received.</li>\n</ul>\n</li>\n<li><code>timingPhases</code> Contains the durations of each request phase. If there were redirects, the properties reflect the timings of the final request in the redirect chain:\n<ul dir=\"auto\">\n<li><code>wait</code>: Duration of socket initialization (<code>timings.socket</code>)</li>\n<li><code>dns</code>: Duration of DNS lookup (<code>timings.lookup</code> - <code>timings.socket</code>)</li>\n<li><code>tcp</code>: Duration of TCP connection (<code>timings.connect</code> - <code>timings.socket</code>)</li>\n<li><code>firstByte</code>: Duration of HTTP server response (<code>timings.response</code> - <code>timings.connect</code>)</li>\n<li><code>download</code>: Duration of HTTP download (<code>timings.end</code> - <code>timings.response</code>)</li>\n<li><code>total</code>: Duration entire HTTP round-trip (<code>timings.end</code>)</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>\n<p dir=\"auto\"><code>har</code> - a <a href=\"http://www.softwareishard.com/blog/har-12-spec/#request\" rel=\"nofollow\">HAR 1.2 Request Object</a>, will be processed from HAR format into options overwriting matching values <em>(see the <a href=\"#support-for-har-12\">HAR 1.2 section</a> for details)</em></p>\n</li>\n<li>\n<p dir=\"auto\"><code>callback</code> - alternatively pass the request's callback in the options object</p>\n</li>\n</ul>\n<p dir=\"auto\">The callback argument gets 3 arguments:</p>\n<ol dir=\"auto\">\n<li>An <code>error</code> when applicable (usually from <a href=\"http://nodejs.org/api/http.html#http_class_http_clientrequest\" rel=\"nofollow\"><code>http.ClientRequest</code></a> object)</li>\n<li>An <a href=\"https://nodejs.org/api/http.html#http_class_http_incomingmessage\" rel=\"nofollow\"><code>http.IncomingMessage</code></a> object (Response object)</li>\n<li>The third is the <code>response</code> body (<code>String</code> or <code>Buffer</code>, or JSON object if the <code>json</code> option is supplied)</li>\n</ol>\n<p dir=\"auto\"><a href=\"#table-of-contents\">back to top</a></p>\n<hr>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">Convenience methods</h2><a id=\"user-content-convenience-methods\" class=\"anchor\" aria-label=\"Permalink: Convenience methods\" href=\"#convenience-methods\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">There are also shorthand methods for different HTTP METHODs and some other conveniences.</p>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">request.defaults(options)</h3><a id=\"user-content-requestdefaultsoptions\" class=\"anchor\" aria-label=\"Permalink: request.defaults(options)\" href=\"#requestdefaultsoptions\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">This method <strong>returns a wrapper</strong> around the normal request API that defaults\nto whatever options you pass to it.</p>\n<p dir=\"auto\"><strong>Note:</strong> <code>request.defaults()</code> <strong>does not</strong> modify the global request API;\ninstead, it <strong>returns a wrapper</strong> that has your default settings applied to it.</p>\n<p dir=\"auto\"><strong>Note:</strong> You can call <code>.defaults()</code> on the wrapper that is returned from\n<code>request.defaults</code> to add/override defaults that were previously defaulted.</p>\n<p dir=\"auto\">For example:</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"//requests using baseRequest() will set the 'x-token' header\nconst baseRequest = request.defaults({\n headers: {'x-token': 'my-token'}\n})\n\n//requests using specialRequest() will include the 'x-token' header set in\n//baseRequest and will also include the 'special' header\nconst specialRequest = baseRequest.defaults({\n headers: {special: 'special value'}\n})\"><pre><span class=\"pl-c\">//requests using baseRequest() will set the 'x-token' header</span>\n<span class=\"pl-k\">const</span> <span class=\"pl-s1\">baseRequest</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">defaults</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">{</span>\n <span class=\"pl-c1\">headers</span>: <span class=\"pl-kos\">{</span><span class=\"pl-s\">'x-token'</span>: <span class=\"pl-s\">'my-token'</span><span class=\"pl-kos\">}</span>\n<span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span>\n\n<span class=\"pl-c\">//requests using specialRequest() will include the 'x-token' header set in</span>\n<span class=\"pl-c\">//baseRequest and will also include the 'special' header</span>\n<span class=\"pl-k\">const</span> <span class=\"pl-s1\">specialRequest</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s1\">baseRequest</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">defaults</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">{</span>\n <span class=\"pl-c1\">headers</span>: <span class=\"pl-kos\">{</span><span class=\"pl-c1\">special</span>: <span class=\"pl-s\">'special value'</span><span class=\"pl-kos\">}</span>\n<span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span></pre></div>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">request.METHOD()</h3><a id=\"user-content-requestmethod\" class=\"anchor\" aria-label=\"Permalink: request.METHOD()\" href=\"#requestmethod\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">These HTTP method convenience functions act just like <code>request()</code> but with a default method already set for you:</p>\n<ul dir=\"auto\">\n<li><em>request.get()</em>: Defaults to <code>method: \"GET\"</code>.</li>\n<li><em>request.post()</em>: Defaults to <code>method: \"POST\"</code>.</li>\n<li><em>request.put()</em>: Defaults to <code>method: \"PUT\"</code>.</li>\n<li><em>request.patch()</em>: Defaults to <code>method: \"PATCH\"</code>.</li>\n<li><em>request.del() / request.delete()</em>: Defaults to <code>method: \"DELETE\"</code>.</li>\n<li><em>request.head()</em>: Defaults to <code>method: \"HEAD\"</code>.</li>\n<li><em>request.options()</em>: Defaults to <code>method: \"OPTIONS\"</code>.</li>\n</ul>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">request.cookie()</h3><a id=\"user-content-requestcookie\" class=\"anchor\" aria-label=\"Permalink: request.cookie()\" href=\"#requestcookie\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">Function that creates a new cookie.</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"request.cookie('key1=value1')\"><pre><span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">cookie</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'key1=value1'</span><span class=\"pl-kos\">)</span></pre></div>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">request.jar()</h3><a id=\"user-content-requestjar\" class=\"anchor\" aria-label=\"Permalink: request.jar()\" href=\"#requestjar\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">Function that creates a new cookie jar.</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"request.jar()\"><pre><span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">jar</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">)</span></pre></div>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">response.caseless.get('header-name')</h3><a id=\"user-content-responsecaselessgetheader-name\" class=\"anchor\" aria-label=\"Permalink: response.caseless.get('header-name')\" href=\"#responsecaselessgetheader-name\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">Function that returns the specified response header field using a <a href=\"https://tools.ietf.org/html/rfc7230#section-3.2\" rel=\"nofollow\">case-insensitive match</a></p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"request('http://www.google.com', function (error, response, body) {\n // print the Content-Type header even if the server returned it as 'content-type' (lowercase)\n console.log('Content-Type is:', response.caseless.get('Content-Type')); \n});\"><pre><span class=\"pl-en\">request</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://www.google.com'</span><span class=\"pl-kos\">,</span> <span class=\"pl-k\">function</span> <span class=\"pl-kos\">(</span><span class=\"pl-s1\">error</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">response</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">body</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-c\">// print the Content-Type header even if the server returned it as 'content-type' (lowercase)</span>\n <span class=\"pl-smi\">console</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">log</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'Content-Type is:'</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">response</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">caseless</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">get</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'Content-Type'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span> \n<span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span></pre></div>\n<p dir=\"auto\"><a href=\"#table-of-contents\">back to top</a></p>\n<hr>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">Debugging</h2><a id=\"user-content-debugging\" class=\"anchor\" aria-label=\"Permalink: Debugging\" href=\"#debugging\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">There are at least three ways to debug the operation of <code>request</code>:</p>\n<ol dir=\"auto\">\n<li>\n<p dir=\"auto\">Launch the node process like <code>NODE_DEBUG=request node script.js</code>\n(<code>lib,request,otherlib</code> works too).</p>\n</li>\n<li>\n<p dir=\"auto\">Set <code>require('request').debug = true</code> at any time (this does the same thing\nas #1).</p>\n</li>\n<li>\n<p dir=\"auto\">Use the <a href=\"https://github.com/request/request-debug\">request-debug module</a> to\nview request and response headers and bodies.</p>\n</li>\n</ol>\n<p dir=\"auto\"><a href=\"#table-of-contents\">back to top</a></p>\n<hr>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">Timeouts</h2><a id=\"user-content-timeouts\" class=\"anchor\" aria-label=\"Permalink: Timeouts\" href=\"#timeouts\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">Most requests to external servers should have a timeout attached, in case the\nserver is not responding in a timely manner. Without a timeout, your code may\nhave a socket open/consume resources for minutes or more.</p>\n<p dir=\"auto\">There are two main types of timeouts: <strong>connection timeouts</strong> and <strong>read\ntimeouts</strong>. A connect timeout occurs if the timeout is hit while your client is\nattempting to establish a connection to a remote machine (corresponding to the\n<a href=\"http://linux.die.net/man/2/connect\" rel=\"nofollow\">connect() call</a> on the socket). A read timeout occurs any time the\nserver is too slow to send back a part of the response.</p>\n<p dir=\"auto\">These two situations have widely different implications for what went wrong\nwith the request, so it's useful to be able to distinguish them. You can detect\ntimeout errors by checking <code>err.code</code> for an 'ETIMEDOUT' value. Further, you\ncan detect whether the timeout was a connection timeout by checking if the\n<code>err.connect</code> property is set to <code>true</code>.</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"request.get('http://10.255.255.1', {timeout: 1500}, function(err) {\n console.log(err.code === 'ETIMEDOUT');\n // Set to `true` if the timeout was a connection timeout, `false` or\n // `undefined` otherwise.\n console.log(err.connect === true);\n process.exit(0);\n});\"><pre><span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">get</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://10.255.255.1'</span><span class=\"pl-kos\">,</span> <span class=\"pl-kos\">{</span><span class=\"pl-c1\">timeout</span>: <span class=\"pl-c1\">1500</span><span class=\"pl-kos\">}</span><span class=\"pl-kos\">,</span> <span class=\"pl-k\">function</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">err</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-smi\">console</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">log</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">err</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">code</span> <span class=\"pl-c1\">===</span> <span class=\"pl-s\">'ETIMEDOUT'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span>\n <span class=\"pl-c\">// Set to `true` if the timeout was a connection timeout, `false` or</span>\n <span class=\"pl-c\">// `undefined` otherwise.</span>\n <span class=\"pl-smi\">console</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">log</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">err</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">connect</span> <span class=\"pl-c1\">===</span> <span class=\"pl-c1\">true</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span>\n <span class=\"pl-s1\">process</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">exit</span><span class=\"pl-kos\">(</span><span class=\"pl-c1\">0</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span>\n<span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span></pre></div>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">Examples:</h2><a id=\"user-content-examples\" class=\"anchor\" aria-label=\"Permalink: Examples:\" href=\"#examples\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\" const request = require('request')\n , rand = Math.floor(Math.random()*100000000).toString()\n ;\n request(\n { method: 'PUT'\n , uri: 'http://mikeal.iriscouch.com/testjs/' + rand\n , multipart:\n [ { 'content-type': 'application/json'\n , body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}})\n }\n , { body: 'I am an attachment' }\n ]\n }\n , function (error, response, body) {\n if(response.statusCode == 201){\n console.log('document saved as: http://mikeal.iriscouch.com/testjs/'+ rand)\n } else {\n console.log('error: '+ response.statusCode)\n console.log(body)\n }\n }\n )\"><pre> <span class=\"pl-k\">const</span> <span class=\"pl-s1\">request</span> <span class=\"pl-c1\">=</span> <span class=\"pl-en\">require</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'request'</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-s1\">rand</span> <span class=\"pl-c1\">=</span> <span class=\"pl-v\">Math</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">floor</span><span class=\"pl-kos\">(</span><span class=\"pl-v\">Math</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">random</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">)</span><span class=\"pl-c1\">*</span><span class=\"pl-c1\">100000000</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">toString</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">;</span>\n <span class=\"pl-s1\">request</span><span class=\"pl-kos\">(</span>\n <span class=\"pl-kos\">{</span> <span class=\"pl-c1\">method</span>: <span class=\"pl-s\">'PUT'</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-c1\">uri</span>: <span class=\"pl-s\">'http://mikeal.iriscouch.com/testjs/'</span> <span class=\"pl-c1\">+</span> <span class=\"pl-s1\">rand</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-c1\">multipart</span>:\n <span class=\"pl-kos\">[</span> <span class=\"pl-kos\">{</span> <span class=\"pl-s\">'content-type'</span>: <span class=\"pl-s\">'application/json'</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-c1\">body</span>: <span class=\"pl-c1\">JSON</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">stringify</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">{</span><span class=\"pl-c1\">foo</span>: <span class=\"pl-s\">'bar'</span><span class=\"pl-kos\">,</span> <span class=\"pl-c1\">_attachments</span>: <span class=\"pl-kos\">{</span><span class=\"pl-s\">'message.txt'</span>: <span class=\"pl-kos\">{</span><span class=\"pl-c1\">follows</span>: <span class=\"pl-c1\">true</span><span class=\"pl-kos\">,</span> <span class=\"pl-c1\">length</span>: <span class=\"pl-c1\">18</span><span class=\"pl-kos\">,</span> <span class=\"pl-s\">'content_type'</span>: <span class=\"pl-s\">'text/plain'</span> <span class=\"pl-kos\">}</span><span class=\"pl-kos\">}</span><span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">}</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-kos\">{</span> <span class=\"pl-c1\">body</span>: <span class=\"pl-s\">'I am an attachment'</span> <span class=\"pl-kos\">}</span>\n <span class=\"pl-kos\">]</span>\n <span class=\"pl-kos\">}</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-k\">function</span> <span class=\"pl-kos\">(</span><span class=\"pl-s1\">error</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">response</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">body</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-k\">if</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">response</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">statusCode</span> <span class=\"pl-c1\">==</span> <span class=\"pl-c1\">201</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">{</span>\n <span class=\"pl-smi\">console</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">log</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'document saved as: http://mikeal.iriscouch.com/testjs/'</span><span class=\"pl-c1\">+</span> <span class=\"pl-s1\">rand</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">}</span> <span class=\"pl-k\">else</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-smi\">console</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">log</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'error: '</span><span class=\"pl-c1\">+</span> <span class=\"pl-s1\">response</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">statusCode</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-smi\">console</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">log</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">body</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">}</span>\n <span class=\"pl-kos\">}</span>\n <span class=\"pl-kos\">)</span></pre></div>\n<p dir=\"auto\">For backwards-compatibility, response compression is not supported by default.\nTo accept gzip-compressed responses, set the <code>gzip</code> option to <code>true</code>. Note\nthat the body data passed through <code>request</code> is automatically decompressed\nwhile the response object is unmodified and will contain compressed data if\nthe server sent a compressed response.</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\" const request = require('request')\n request(\n { method: 'GET'\n , uri: 'http://www.google.com'\n , gzip: true\n }\n , function (error, response, body) {\n // body is the decompressed response body\n console.log('server encoded the data as: ' + (response.headers['content-encoding'] || 'identity'))\n console.log('the decoded data is: ' + body)\n }\n )\n .on('data', function(data) {\n // decompressed data as it is received\n console.log('decoded chunk: ' + data)\n })\n .on('response', function(response) {\n // unmodified http.IncomingMessage object\n response.on('data', function(data) {\n // compressed data as it is received\n console.log('received ' + data.length + ' bytes of compressed data')\n })\n })\"><pre> <span class=\"pl-k\">const</span> <span class=\"pl-s1\">request</span> <span class=\"pl-c1\">=</span> <span class=\"pl-en\">require</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'request'</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-s1\">request</span><span class=\"pl-kos\">(</span>\n <span class=\"pl-kos\">{</span> <span class=\"pl-c1\">method</span>: <span class=\"pl-s\">'GET'</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-c1\">uri</span>: <span class=\"pl-s\">'http://www.google.com'</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-c1\">gzip</span>: <span class=\"pl-c1\">true</span>\n <span class=\"pl-kos\">}</span>\n <span class=\"pl-kos\">,</span> <span class=\"pl-k\">function</span> <span class=\"pl-kos\">(</span><span class=\"pl-s1\">error</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">response</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">body</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-c\">// body is the decompressed response body</span>\n <span class=\"pl-smi\">console</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">log</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'server encoded the data as: '</span> <span class=\"pl-c1\">+</span> <span class=\"pl-kos\">(</span><span class=\"pl-s1\">response</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">headers</span><span class=\"pl-kos\">[</span><span class=\"pl-s\">'content-encoding'</span><span class=\"pl-kos\">]</span> <span class=\"pl-c1\">||</span> <span class=\"pl-s\">'identity'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-smi\">console</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">log</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'the decoded data is: '</span> <span class=\"pl-c1\">+</span> <span class=\"pl-s1\">body</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">}</span>\n <span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">.</span><span class=\"pl-en\">on</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'data'</span><span class=\"pl-kos\">,</span> <span class=\"pl-k\">function</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">data</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-c\">// decompressed data as it is received</span>\n <span class=\"pl-smi\">console</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">log</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'decoded chunk: '</span> <span class=\"pl-c1\">+</span> <span class=\"pl-s1\">data</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">.</span><span class=\"pl-en\">on</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'response'</span><span class=\"pl-kos\">,</span> <span class=\"pl-k\">function</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">response</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-c\">// unmodified http.IncomingMessage object</span>\n <span class=\"pl-s1\">response</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">on</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'data'</span><span class=\"pl-kos\">,</span> <span class=\"pl-k\">function</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">data</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-c\">// compressed data as it is received</span>\n <span class=\"pl-smi\">console</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">log</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'received '</span> <span class=\"pl-c1\">+</span> <span class=\"pl-s1\">data</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">length</span> <span class=\"pl-c1\">+</span> <span class=\"pl-s\">' bytes of compressed data'</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span>\n <span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span></pre></div>\n<p dir=\"auto\">Cookies are disabled by default (else, they would be used in subsequent requests). To enable cookies, set <code>jar</code> to <code>true</code> (either in <code>defaults</code> or <code>options</code>).</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"const request = request.defaults({jar: true})\nrequest('http://www.google.com', function () {\n request('http://images.google.com')\n})\"><pre><span class=\"pl-k\">const</span> <span class=\"pl-s1\">request</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">defaults</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">{</span><span class=\"pl-c1\">jar</span>: <span class=\"pl-c1\">true</span><span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span>\n<span class=\"pl-s1\">request</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://www.google.com'</span><span class=\"pl-kos\">,</span> <span class=\"pl-k\">function</span> <span class=\"pl-kos\">(</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-s1\">request</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://images.google.com'</span><span class=\"pl-kos\">)</span>\n<span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span></pre></div>\n<p dir=\"auto\">To use a custom cookie jar (instead of <code>request</code>’s global cookie jar), set <code>jar</code> to an instance of <code>request.jar()</code> (either in <code>defaults</code> or <code>options</code>)</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"const j = request.jar()\nconst request = request.defaults({jar:j})\nrequest('http://www.google.com', function () {\n request('http://images.google.com')\n})\"><pre><span class=\"pl-k\">const</span> <span class=\"pl-s1\">j</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">jar</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">)</span>\n<span class=\"pl-k\">const</span> <span class=\"pl-s1\">request</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">defaults</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">{</span><span class=\"pl-c1\">jar</span>:<span class=\"pl-s1\">j</span><span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span>\n<span class=\"pl-s1\">request</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://www.google.com'</span><span class=\"pl-kos\">,</span> <span class=\"pl-k\">function</span> <span class=\"pl-kos\">(</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-s1\">request</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://images.google.com'</span><span class=\"pl-kos\">)</span>\n<span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span></pre></div>\n<p dir=\"auto\">OR</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"const j = request.jar();\nconst cookie = request.cookie('key1=value1');\nconst url = 'http://www.google.com';\nj.setCookie(cookie, url);\nrequest({url: url, jar: j}, function () {\n request('http://images.google.com')\n})\"><pre><span class=\"pl-k\">const</span> <span class=\"pl-s1\">j</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">jar</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span>\n<span class=\"pl-k\">const</span> <span class=\"pl-s1\">cookie</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">cookie</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'key1=value1'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span>\n<span class=\"pl-k\">const</span> <span class=\"pl-s1\">url</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s\">'http://www.google.com'</span><span class=\"pl-kos\">;</span>\n<span class=\"pl-s1\">j</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">setCookie</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">cookie</span><span class=\"pl-kos\">,</span> <span class=\"pl-s1\">url</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span>\n<span class=\"pl-en\">request</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">{</span><span class=\"pl-c1\">url</span>: <span class=\"pl-s1\">url</span><span class=\"pl-kos\">,</span> <span class=\"pl-c1\">jar</span>: <span class=\"pl-s1\">j</span><span class=\"pl-kos\">}</span><span class=\"pl-kos\">,</span> <span class=\"pl-k\">function</span> <span class=\"pl-kos\">(</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-en\">request</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://images.google.com'</span><span class=\"pl-kos\">)</span>\n<span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span></pre></div>\n<p dir=\"auto\">To use a custom cookie store (such as a\n<a href=\"https://github.com/mitsuru/tough-cookie-filestore\"><code>FileCookieStore</code></a>\nwhich supports saving to and restoring from JSON files), pass it as a parameter\nto <code>request.jar()</code>:</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"const FileCookieStore = require('tough-cookie-filestore');\n// NOTE - currently the 'cookies.json' file must already exist!\nconst j = request.jar(new FileCookieStore('cookies.json'));\nrequest = request.defaults({ jar : j })\nrequest('http://www.google.com', function() {\n request('http://images.google.com')\n})\"><pre><span class=\"pl-k\">const</span> <span class=\"pl-v\">FileCookieStore</span> <span class=\"pl-c1\">=</span> <span class=\"pl-en\">require</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'tough-cookie-filestore'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span>\n<span class=\"pl-c\">// NOTE - currently the 'cookies.json' file must already exist!</span>\n<span class=\"pl-k\">const</span> <span class=\"pl-s1\">j</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">jar</span><span class=\"pl-kos\">(</span><span class=\"pl-k\">new</span> <span class=\"pl-v\">FileCookieStore</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'cookies.json'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span>\n<span class=\"pl-s1\">request</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">defaults</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">{</span> <span class=\"pl-c1\">jar</span> : <span class=\"pl-s1\">j</span> <span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span>\n<span class=\"pl-en\">request</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://www.google.com'</span><span class=\"pl-kos\">,</span> <span class=\"pl-k\">function</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-en\">request</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'http://images.google.com'</span><span class=\"pl-kos\">)</span>\n<span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span></pre></div>\n<p dir=\"auto\">The cookie store must be a\n<a href=\"https://github.com/SalesforceEng/tough-cookie\"><code>tough-cookie</code></a>\nstore and it must support synchronous operations; see the\n<a href=\"https://github.com/SalesforceEng/tough-cookie#api\"><code>CookieStore</code> API docs</a>\nfor details.</p>\n<p dir=\"auto\">To inspect your cookie jar after a request:</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"const j = request.jar()\nrequest({url: 'http://www.google.com', jar: j}, function () {\n const cookie_string = j.getCookieString(url); // &quot;key1=value1; key2=value2; ...&quot;\n const cookies = j.getCookies(url);\n // [{key: 'key1', value: 'value1', domain: &quot;www.google.com&quot;, ...}, ...]\n})\"><pre><span class=\"pl-k\">const</span> <span class=\"pl-s1\">j</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s1\">request</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">jar</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">)</span>\n<span class=\"pl-en\">request</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">{</span><span class=\"pl-c1\">url</span>: <span class=\"pl-s\">'http://www.google.com'</span><span class=\"pl-kos\">,</span> <span class=\"pl-c1\">jar</span>: <span class=\"pl-s1\">j</span><span class=\"pl-kos\">}</span><span class=\"pl-kos\">,</span> <span class=\"pl-k\">function</span> <span class=\"pl-kos\">(</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-k\">const</span> <span class=\"pl-s1\">cookie_string</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s1\">j</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">getCookieString</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">url</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span> <span class=\"pl-c\">// \"key1=value1; key2=value2; ...\"</span>\n <span class=\"pl-k\">const</span> <span class=\"pl-s1\">cookies</span> <span class=\"pl-c1\">=</span> <span class=\"pl-s1\">j</span><span class=\"pl-kos\">.</span><span class=\"pl-en\">getCookies</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">url</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">;</span>\n <span class=\"pl-c\">// [{key: 'key1', value: 'value1', domain: \"www.google.com\", ...}, ...]</span>\n<span class=\"pl-kos\">}</span><span class=\"pl-kos\">)</span></pre></div>\n<p dir=\"auto\"><a href=\"#table-of-contents\">back to top</a></p>\n</article>",
"loaded": true,
"timedOut": false,
"errorMessage": null,
"headerInfo": {
"toc": [
{
"level": 1,
"text": "Deprecated!",
"anchor": "deprecated",
"htmlText": "Deprecated!"
},
{
"level": 1,
"text": "Request - Simplified HTTP client",
"anchor": "request---simplified-http-client",
"htmlText": "Request - Simplified HTTP client"
},
{
"level": 2,
"text": "Super simple to use",
"anchor": "super-simple-to-use",
"htmlText": "Super simple to use"
},
{
"level": 2,
"text": "Table of contents",
"anchor": "table-of-contents",
"htmlText": "Table of contents"
},
{
"level": 2,
"text": "Streaming",
"anchor": "streaming",
"htmlText": "Streaming"
},
{
"level": 2,
"text": "Promises & Async/Await",
"anchor": "promises--asyncawait",
"htmlText": "Promises &amp; Async/Await"
},
{
"level": 2,
"text": "Forms",
"anchor": "forms",
"htmlText": "Forms"
},
{
"level": 4,
"text": "application/x-www-form-urlencoded (URL-Encoded Forms)",
"anchor": "applicationx-www-form-urlencoded-url-encoded-forms",
"htmlText": "application/x-www-form-urlencoded (URL-Encoded Forms)"
},
{
"level": 4,
"text": "multipart/form-data (Multipart Form Uploads)",
"anchor": "multipartform-data-multipart-form-uploads",
"htmlText": "multipart/form-data (Multipart Form Uploads)"
},
{
"level": 4,
"text": "multipart/related",
"anchor": "multipartrelated",
"htmlText": "multipart/related"
},
{
"level": 2,
"text": "HTTP Authentication",
"anchor": "http-authentication",
"htmlText": "HTTP Authentication"
},
{
"level": 2,
"text": "Custom HTTP Headers",
"anchor": "custom-http-headers",
"htmlText": "Custom HTTP Headers"
},
{
"level": 2,
"text": "OAuth Signing",
"anchor": "oauth-signing",
"htmlText": "OAuth Signing"
},
{
"level": 2,
"text": "Proxies",
"anchor": "proxies",
"htmlText": "Proxies"
},
{
"level": 3,
"text": "Controlling proxy behaviour using environment variables",
"anchor": "controlling-proxy-behaviour-using-environment-variables",
"htmlText": "Controlling proxy behaviour using environment variables"
},
{
"level": 2,
"text": "UNIX Domain Sockets",
"anchor": "unix-domain-sockets",
"htmlText": "UNIX Domain Sockets"
},
{
"level": 2,
"text": "TLS/SSL Protocol",
"anchor": "tlsssl-protocol",
"htmlText": "TLS/SSL Protocol"
},
{
"level": 3,
"text": "Using options.agentOptions",
"anchor": "using-optionsagentoptions",
"htmlText": "Using options.agentOptions"
},
{
"level": 2,
"text": "Support for HAR 1.2",
"anchor": "support-for-har-12",
"htmlText": "Support for HAR 1.2"
},
{
"level": 2,
"text": "request(options, callback)",
"anchor": "requestoptions-callback",
"htmlText": "request(options, callback)"
},
{
"level": 2,
"text": "Convenience methods",
"anchor": "convenience-methods",
"htmlText": "Convenience methods"
},
{
"level": 3,
"text": "request.defaults(options)",
"anchor": "requestdefaultsoptions",
"htmlText": "request.defaults(options)"
},
{
"level": 3,
"text": "request.METHOD()",
"anchor": "requestmethod",
"htmlText": "request.METHOD()"
},
{
"level": 3,
"text": "request.cookie()",
"anchor": "requestcookie",
"htmlText": "request.cookie()"
},
{
"level": 3,
"text": "request.jar()",
"anchor": "requestjar",
"htmlText": "request.jar()"
},
{
"level": 3,
"text": "response.caseless.get('header-name')",
"anchor": "responsecaselessgetheader-name",
"htmlText": "response.caseless.get('header-name')"
},
{
"level": 2,
"text": "Debugging",
"anchor": "debugging",
"htmlText": "Debugging"
},
{
"level": 2,
"text": "Timeouts",
"anchor": "timeouts",
"htmlText": "Timeouts"
},
{
"level": 2,
"text": "Examples:",
"anchor": "examples",
"htmlText": "Examples:"
}
],
"siteNavLoginPath": "/login?return_to=https%3A%2F%2Fgithub.com%2Frequest%2Frequest"
}
},
{
"displayName": "LICENSE",
"repoName": "request",
"refName": "master",
"path": "LICENSE",
"preferredFileType": "license",
"tabName": "Apache-2.0",
"richText": null,
"loaded": false,
"timedOut": false,
"errorMessage": null,
"headerInfo": {
"toc": null,
"siteNavLoginPath": "/login?return_to=https%3A%2F%2Fgithub.com%2Frequest%2Frequest"
}
}
],
"overviewFilesProcessingTime": 0
}
},
"appPayload": {
"helpUrl": "https://docs.github.com",
"findFileWorkerPath": "/assets-cdn/worker/find-file-worker-1583894afd38.js",
"findInFileWorkerPath": "/assets-cdn/worker/find-in-file-worker-3a63a487027b.js",
"githubDevUrl": null,
"enabled_features": {
"code_nav_ui_events": false,
"overview_shared_code_dropdown_button": false,
"react_blob_overlay": false,
"copilot_conversational_ux_embedding_update": false,
"copilot_smell_icebreaker_ux": true,
"copilot_workspace": false
}
}
}
}
{
"accept-ranges": "bytes",
"cache-control": "max-age=0, private, must-revalidate",
"content-encoding": "gzip",
"content-security-policy": "default-src 'none'; base-uri 'self'; child-src github.com/assets-cdn/worker/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com api.githubcopilot.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com/v1/engines/github-completion/completions proxy.enterprise.githubcopilot.com/v1/engines/github-completion/completions *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.com/assets-cdn/worker/ gist.github.com/assets-cdn/worker/",
"content-type": "text/html; charset=utf-8",
"date": "Sat, 27 Jul 2024 02:39:06 GMT",
"etag": "e24e1f71c737b2f64345f30ec4e2b432",
"referrer-policy": "no-referrer-when-downgrade",
"server": "GitHub.com",
"set-cookie": "logged_in=no; Path=/; Domain=github.com; Expires=Sun, 27 Jul 2025 02:39:06 GMT; HttpOnly; Secure; SameSite=Lax",
"strict-transport-security": "max-age=31536000; includeSubdomains; preload",
"transfer-encoding": "chunked",
"vary": "X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, Accept-Encoding, Accept, X-Requested-With",
"x-content-type-options": "nosniff",
"x-frame-options": "deny",
"x-github-request-id": "C7B2:152E40:2EFBA3:3B01F7:66A45DCA",
"x-xss-protection": "0"
}