angular-slickgrid 4.1.4 → 4.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/README.md +182 -180
  2. package/app/modules/angular-slickgrid/components/angular-slickgrid.component.d.ts +2 -2
  3. package/app/modules/angular-slickgrid/extensions/slickRowDetailView.d.ts +0 -2
  4. package/esm2020/app/modules/angular-slickgrid/components/angular-slickgrid.component.mjs +15 -12
  5. package/esm2020/app/modules/angular-slickgrid/extensions/slickRowDetailView.mjs +1 -3
  6. package/esm2020/app/modules/angular-slickgrid/modules/angular-slickgrid.module.mjs +7 -10
  7. package/esm2020/app/modules/angular-slickgrid/services/angularUtil.service.mjs +3 -3
  8. package/esm2020/app/modules/angular-slickgrid/services/bsDropdown.service.mjs +3 -3
  9. package/esm2020/app/modules/angular-slickgrid/services/container.service.mjs +3 -3
  10. package/esm2020/app/modules/angular-slickgrid/services/translater.service.mjs +3 -3
  11. package/fesm2015/angular-slickgrid.mjs +32 -34
  12. package/fesm2015/angular-slickgrid.mjs.map +1 -1
  13. package/fesm2020/angular-slickgrid.mjs +32 -34
  14. package/fesm2020/angular-slickgrid.mjs.map +1 -1
  15. package/{angular-slickgrid.d.ts → index.d.ts} +0 -0
  16. package/package.json +14 -15
  17. package/test/cypress/node_modules/@cypress/request/README.md +1038 -0
  18. package/test/cypress/node_modules/@cypress/xvfb/README.md +48 -0
  19. package/test/cypress/node_modules/@cypress/xvfb/node_modules/debug/README.md +437 -0
  20. package/test/cypress/node_modules/@types/node/README.md +16 -0
  21. package/test/cypress/node_modules/@types/sinonjs__fake-timers/README.md +16 -0
  22. package/test/cypress/node_modules/@types/sizzle/README.md +16 -0
  23. package/test/cypress/node_modules/@types/yauzl/README.md +16 -0
  24. package/test/cypress/node_modules/@types/yauzl/node_modules/@types/node/README.md +16 -0
  25. package/test/cypress/node_modules/aggregate-error/README.md +61 -0
  26. package/test/cypress/node_modules/ansi-colors/README.md +315 -0
  27. package/test/cypress/node_modules/ansi-escapes/README.md +245 -0
  28. package/test/cypress/node_modules/ansi-regex/README.md +78 -0
  29. package/test/cypress/node_modules/ansi-styles/README.md +152 -0
  30. package/test/cypress/node_modules/arch/README.md +71 -0
  31. package/test/cypress/node_modules/asn1/README.md +50 -0
  32. package/test/cypress/node_modules/assert-plus/README.md +162 -0
  33. package/test/cypress/node_modules/astral-regex/README.md +46 -0
  34. package/test/cypress/node_modules/async/README.md +60 -0
  35. package/test/cypress/node_modules/asynckit/README.md +233 -0
  36. package/test/cypress/node_modules/at-least-node/README.md +25 -0
  37. package/test/cypress/node_modules/aws-sign2/README.md +4 -0
  38. package/test/cypress/node_modules/aws4/README.md +183 -0
  39. package/test/cypress/node_modules/balanced-match/README.md +91 -0
  40. package/test/cypress/node_modules/base64-js/README.md +34 -0
  41. package/test/cypress/node_modules/bcrypt-pbkdf/README.md +45 -0
  42. package/test/cypress/node_modules/blob-util/README.md +623 -0
  43. package/test/cypress/node_modules/bluebird/README.md +57 -0
  44. package/test/cypress/node_modules/brace-expansion/README.md +129 -0
  45. package/test/cypress/node_modules/buffer/README.md +410 -0
  46. package/test/cypress/node_modules/buffer-crc32/README.md +47 -0
  47. package/test/cypress/node_modules/cachedir/README.md +27 -0
  48. package/test/cypress/node_modules/caseless/README.md +45 -0
  49. package/test/cypress/node_modules/chalk/README.md +293 -0
  50. package/test/cypress/node_modules/chalk/node_modules/supports-color/README.md +76 -0
  51. package/test/cypress/node_modules/check-more-types/README.md +952 -0
  52. package/test/cypress/node_modules/ci-info/README.md +114 -0
  53. package/test/cypress/node_modules/clean-stack/README.md +76 -0
  54. package/test/cypress/node_modules/cli-cursor/README.md +55 -0
  55. package/test/cypress/node_modules/cli-table3/README.md +218 -0
  56. package/test/cypress/node_modules/cli-truncate/README.md +139 -0
  57. package/test/cypress/node_modules/color-convert/README.md +68 -0
  58. package/test/cypress/node_modules/color-name/README.md +11 -0
  59. package/test/cypress/node_modules/colorette/README.md +102 -0
  60. package/test/cypress/node_modules/colors/README.md +221 -0
  61. package/test/cypress/node_modules/combined-stream/README.md +138 -0
  62. package/test/cypress/node_modules/commander/README.md +737 -0
  63. package/test/cypress/node_modules/common-tags/README.md +687 -0
  64. package/test/cypress/node_modules/core-util-is/README.md +3 -0
  65. package/test/cypress/node_modules/cross-spawn/README.md +96 -0
  66. package/test/cypress/node_modules/cypress/README.md +25 -0
  67. package/test/cypress/node_modules/cypress/mount-utils/README.md +14 -0
  68. package/test/cypress/node_modules/cypress/react/README.md +414 -0
  69. package/test/cypress/node_modules/cypress/vue/README.md +678 -0
  70. package/test/cypress/node_modules/cypress/vue2/README.md +693 -0
  71. package/test/cypress/node_modules/dashdash/README.md +574 -0
  72. package/test/cypress/node_modules/dayjs/README.md +128 -0
  73. package/test/cypress/node_modules/debug/README.md +455 -0
  74. package/test/cypress/node_modules/delayed-stream/README.md +141 -0
  75. package/test/cypress/node_modules/ecc-jsbn/README.md +8 -0
  76. package/test/cypress/node_modules/emoji-regex/README.md +73 -0
  77. package/test/cypress/node_modules/end-of-stream/README.md +54 -0
  78. package/test/cypress/node_modules/enquirer/README.md +1752 -0
  79. package/test/cypress/node_modules/escape-string-regexp/README.md +27 -0
  80. package/test/cypress/node_modules/eventemitter2/README.md +809 -0
  81. package/test/cypress/node_modules/execa/README.md +656 -0
  82. package/test/cypress/node_modules/executable/README.md +64 -0
  83. package/test/cypress/node_modules/extend/README.md +81 -0
  84. package/test/cypress/node_modules/extract-zip/README.md +57 -0
  85. package/test/cypress/node_modules/extract-zip/node_modules/debug/README.md +455 -0
  86. package/test/cypress/node_modules/extsprintf/README.md +46 -0
  87. package/test/cypress/node_modules/fd-slicer/README.md +199 -0
  88. package/test/cypress/node_modules/figures/README.md +139 -0
  89. package/test/cypress/node_modules/forever-agent/README.md +4 -0
  90. package/test/cypress/node_modules/form-data/README.md +234 -0
  91. package/test/cypress/node_modules/fs-extra/README.md +264 -0
  92. package/test/cypress/node_modules/fs.realpath/README.md +33 -0
  93. package/test/cypress/node_modules/get-stream/README.md +124 -0
  94. package/test/cypress/node_modules/getos/README.md +79 -0
  95. package/test/cypress/node_modules/getpass/README.md +32 -0
  96. package/test/cypress/node_modules/glob/README.md +375 -0
  97. package/test/cypress/node_modules/global-dirs/README.md +72 -0
  98. package/test/cypress/node_modules/graceful-fs/README.md +133 -0
  99. package/test/cypress/node_modules/has-flag/README.md +89 -0
  100. package/test/cypress/node_modules/http-signature/README.md +80 -0
  101. package/test/cypress/node_modules/human-signals/README.md +155 -0
  102. package/test/cypress/node_modules/ieee754/README.md +51 -0
  103. package/test/cypress/node_modules/indent-string/README.md +70 -0
  104. package/test/cypress/node_modules/inflight/README.md +37 -0
  105. package/test/cypress/node_modules/inherits/README.md +42 -0
  106. package/test/cypress/node_modules/ini/README.md +102 -0
  107. package/test/cypress/node_modules/is-ci/README.md +50 -0
  108. package/test/cypress/node_modules/is-fullwidth-code-point/README.md +39 -0
  109. package/test/cypress/node_modules/is-installed-globally/README.md +31 -0
  110. package/test/cypress/node_modules/is-path-inside/README.md +63 -0
  111. package/test/cypress/node_modules/is-stream/README.md +57 -0
  112. package/test/cypress/node_modules/is-typedarray/README.md +16 -0
  113. package/test/cypress/node_modules/isexe/README.md +51 -0
  114. package/test/cypress/node_modules/isstream/README.md +66 -0
  115. package/test/cypress/node_modules/jsbn/README.md +175 -0
  116. package/test/cypress/node_modules/json-schema/README.md +3 -0
  117. package/test/cypress/node_modules/json-stringify-safe/README.md +52 -0
  118. package/test/cypress/node_modules/jsonfile/README.md +205 -0
  119. package/test/cypress/node_modules/jsonfile/node_modules/universalify/README.md +76 -0
  120. package/test/cypress/node_modules/jsprim/README.md +287 -0
  121. package/test/cypress/node_modules/lazy-ass/README.md +269 -0
  122. package/test/cypress/node_modules/listr2/README.md +17 -0
  123. package/test/cypress/node_modules/lodash/README.md +39 -0
  124. package/test/cypress/node_modules/lodash.once/README.md +18 -0
  125. package/test/cypress/node_modules/log-symbols/README.md +51 -0
  126. package/test/cypress/node_modules/log-update/README.md +97 -0
  127. package/test/cypress/node_modules/log-update/node_modules/slice-ansi/README.md +66 -0
  128. package/test/cypress/node_modules/log-update/node_modules/wrap-ansi/README.md +97 -0
  129. package/test/cypress/node_modules/lru-cache/README.md +166 -0
  130. package/test/cypress/node_modules/merge-stream/README.md +78 -0
  131. package/test/cypress/node_modules/mime-db/README.md +102 -0
  132. package/test/cypress/node_modules/mime-types/README.md +123 -0
  133. package/test/cypress/node_modules/mimic-fn/README.md +69 -0
  134. package/test/cypress/node_modules/minimatch/README.md +209 -0
  135. package/test/cypress/node_modules/ms/README.md +60 -0
  136. package/test/cypress/node_modules/npm-run-path/README.md +115 -0
  137. package/test/cypress/node_modules/once/README.md +79 -0
  138. package/test/cypress/node_modules/onetime/README.md +94 -0
  139. package/test/cypress/node_modules/ospath/README.md +53 -0
  140. package/test/cypress/node_modules/p-map/README.md +89 -0
  141. package/test/cypress/node_modules/path-is-absolute/README.md +59 -0
  142. package/test/cypress/node_modules/path-key/README.md +61 -0
  143. package/test/cypress/node_modules/pend/README.md +41 -0
  144. package/test/cypress/node_modules/performance-now/README.md +30 -0
  145. package/test/cypress/node_modules/pify/README.md +119 -0
  146. package/test/cypress/node_modules/pretty-bytes/README.md +131 -0
  147. package/test/cypress/node_modules/proxy-from-env/README.md +131 -0
  148. package/test/cypress/node_modules/psl/README.md +215 -0
  149. package/test/cypress/node_modules/pump/README.md +65 -0
  150. package/test/cypress/node_modules/punycode/README.md +122 -0
  151. package/test/cypress/node_modules/qs/README.md +475 -0
  152. package/test/cypress/node_modules/request-progress/README.md +78 -0
  153. package/test/cypress/node_modules/restore-cursor/README.md +26 -0
  154. package/test/cypress/node_modules/rimraf/README.md +101 -0
  155. package/test/cypress/node_modules/rxjs/README.md +147 -0
  156. package/test/cypress/node_modules/rxjs/_esm2015/README.md +147 -0
  157. package/test/cypress/node_modules/rxjs/_esm5/README.md +147 -0
  158. package/test/cypress/node_modules/rxjs/src/README.md +147 -0
  159. package/test/cypress/node_modules/safe-buffer/README.md +584 -0
  160. package/test/cypress/node_modules/safer-buffer/README.md +156 -0
  161. package/test/cypress/node_modules/semver/README.md +566 -0
  162. package/test/cypress/node_modules/shebang-command/README.md +34 -0
  163. package/test/cypress/node_modules/shebang-regex/README.md +33 -0
  164. package/test/cypress/node_modules/signal-exit/README.md +39 -0
  165. package/test/cypress/node_modules/slice-ansi/README.md +72 -0
  166. package/test/cypress/node_modules/sshpk/README.md +804 -0
  167. package/test/cypress/node_modules/string-width/README.md +50 -0
  168. package/test/cypress/node_modules/strip-ansi/README.md +46 -0
  169. package/test/cypress/node_modules/strip-final-newline/README.md +30 -0
  170. package/test/cypress/node_modules/supports-color/README.md +77 -0
  171. package/test/cypress/node_modules/throttleit/README.md +32 -0
  172. package/test/cypress/node_modules/tmp/README.md +365 -0
  173. package/test/cypress/node_modules/tough-cookie/README.md +527 -0
  174. package/test/cypress/node_modules/tslib/README.md +142 -0
  175. package/test/cypress/node_modules/tunnel-agent/README.md +4 -0
  176. package/test/cypress/node_modules/tweetnacl/README.md +459 -0
  177. package/test/cypress/node_modules/type-fest/README.md +760 -0
  178. package/test/cypress/node_modules/universalify/README.md +76 -0
  179. package/test/cypress/node_modules/untildify/README.md +30 -0
  180. package/test/cypress/node_modules/uuid/README.md +505 -0
  181. package/test/cypress/node_modules/verror/README.md +528 -0
  182. package/test/cypress/node_modules/verror/node_modules/extsprintf/README.md +46 -0
  183. package/test/cypress/node_modules/which/README.md +54 -0
  184. package/test/cypress/node_modules/wrap-ansi/README.md +91 -0
  185. package/test/cypress/node_modules/wrappy/README.md +36 -0
  186. package/test/cypress/node_modules/yallist/README.md +204 -0
  187. package/test/cypress/node_modules/yauzl/README.md +658 -0
@@ -0,0 +1,1038 @@
1
+
2
+ # @cypress/request - Simplified HTTP client
3
+
4
+ [![npm package](https://nodei.co/npm/@cypress/request.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/@cypress/request/)
5
+
6
+ [![Build status](https://img.shields.io/travis/cypress-io/request/master.svg?style=flat-square)](https://travis-ci.org/cypress-io/request)
7
+ [![Coverage](https://img.shields.io/codecov/c/github/cypress-io/request.svg?style=flat-square)](https://codecov.io/github/cypress-io/request?branch=master)
8
+ [![Coverage](https://img.shields.io/coveralls/cypress-io/request.svg?style=flat-square)](https://coveralls.io/r/cypress-io/request)
9
+ [![Dependency Status](https://img.shields.io/david/cypress-io/request.svg?style=flat-square)](https://david-dm.org/cypress-io/request)
10
+ [![Known Vulnerabilities](https://snyk.io/test/npm/request/badge.svg?style=flat-square)](https://snyk.io/test/npm/request)
11
+ [![Gitter](https://img.shields.io/badge/gitter-join_chat-blue.svg?style=flat-square)](https://gitter.im/cypress-io/request?utm_source=badge)
12
+
13
+ **This is a fork of [`request`](https://github.com/request/request) for use in [Cypress](https://github.com/cypress-io/cypress).**
14
+
15
+ ## Super simple to use
16
+
17
+ Request is designed to be the simplest way possible to make http calls. It supports HTTPS and follows redirects by default.
18
+
19
+ ```js
20
+ const request = require('@cypress/request');
21
+ request('http://www.google.com', function (error, response, body) {
22
+ console.error('error:', error); // Print the error if one occurred
23
+ console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
24
+ console.log('body:', body); // Print the HTML for the Google homepage.
25
+ });
26
+ ```
27
+
28
+
29
+ ## Table of contents
30
+
31
+ - [Streaming](#streaming)
32
+ - [Promises & Async/Await](#promises--asyncawait)
33
+ - [Forms](#forms)
34
+ - [HTTP Authentication](#http-authentication)
35
+ - [Custom HTTP Headers](#custom-http-headers)
36
+ - [Proxies](#proxies)
37
+ - [Unix Domain Sockets](#unix-domain-sockets)
38
+ - [TLS/SSL Protocol](#tlsssl-protocol)
39
+ - [Support for HAR 1.2](#support-for-har-12)
40
+ - [**All Available Options**](#requestoptions-callback)
41
+
42
+ Request also offers [convenience methods](#convenience-methods) like
43
+ `request.defaults` and `request.post`, and there are
44
+ lots of [usage examples](#examples) and several
45
+ [debugging techniques](#debugging).
46
+
47
+
48
+ ---
49
+
50
+
51
+ ## Streaming
52
+
53
+ You can stream any response to a file stream.
54
+
55
+ ```js
56
+ request('http://google.com/doodle.png').pipe(fs.createWriteStream('doodle.png'))
57
+ ```
58
+
59
+ 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).
60
+
61
+ ```js
62
+ fs.createReadStream('file.json').pipe(request.put('http://mysite.com/obj.json'))
63
+ ```
64
+
65
+ Request can also `pipe` to itself. When doing so, `content-type` and `content-length` are preserved in the PUT headers.
66
+
67
+ ```js
68
+ request.get('http://google.com/img.png').pipe(request.put('http://mysite.com/img.png'))
69
+ ```
70
+
71
+ Request emits a "response" event when a response is received. The `response` argument will be an instance of [http.IncomingMessage](https://nodejs.org/api/http.html#http_class_http_incomingmessage).
72
+
73
+ ```js
74
+ request
75
+ .get('http://google.com/img.png')
76
+ .on('response', function(response) {
77
+ console.log(response.statusCode) // 200
78
+ console.log(response.headers['content-type']) // 'image/png'
79
+ })
80
+ .pipe(request.put('http://mysite.com/img.png'))
81
+ ```
82
+
83
+ To easily handle errors when streaming requests, listen to the `error` event before piping:
84
+
85
+ ```js
86
+ request
87
+ .get('http://mysite.com/doodle.png')
88
+ .on('error', function(err) {
89
+ console.error(err)
90
+ })
91
+ .pipe(fs.createWriteStream('doodle.png'))
92
+ ```
93
+
94
+ Now let’s get fancy.
95
+
96
+ ```js
97
+ http.createServer(function (req, resp) {
98
+ if (req.url === '/doodle.png') {
99
+ if (req.method === 'PUT') {
100
+ req.pipe(request.put('http://mysite.com/doodle.png'))
101
+ } else if (req.method === 'GET' || req.method === 'HEAD') {
102
+ request.get('http://mysite.com/doodle.png').pipe(resp)
103
+ }
104
+ }
105
+ })
106
+ ```
107
+
108
+ 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:
109
+
110
+ ```js
111
+ http.createServer(function (req, resp) {
112
+ if (req.url === '/doodle.png') {
113
+ const x = request('http://mysite.com/doodle.png')
114
+ req.pipe(x)
115
+ x.pipe(resp)
116
+ }
117
+ })
118
+ ```
119
+
120
+ And since `pipe()` returns the destination stream in ≥ Node 0.5.x you can do one line proxying. :)
121
+
122
+ ```js
123
+ req.pipe(request('http://mysite.com/doodle.png')).pipe(resp)
124
+ ```
125
+
126
+ Also, none of this new functionality conflicts with requests previous features, it just expands them.
127
+
128
+ ```js
129
+ const r = request.defaults({'proxy':'http://localproxy.com'})
130
+
131
+ http.createServer(function (req, resp) {
132
+ if (req.url === '/doodle.png') {
133
+ r.get('http://google.com/doodle.png').pipe(resp)
134
+ }
135
+ })
136
+ ```
137
+
138
+ You can still use intermediate proxies, the requests will still follow HTTP forwards, etc.
139
+
140
+ [back to top](#table-of-contents)
141
+
142
+
143
+ ---
144
+
145
+
146
+ ## Promises & Async/Await
147
+
148
+ `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.
149
+
150
+ Several alternative interfaces are provided by the request team, including:
151
+ - [`request-promise`](https://github.com/cypress-io/request-promise) (uses [Bluebird](https://github.com/petkaantonov/bluebird) Promises)
152
+ - [`request-promise-native`](https://github.com/cypress-io/request-promise-native) (uses native Promises)
153
+ - [`request-promise-any`](https://github.com/cypress-io/request-promise-any) (uses [any-promise](https://www.npmjs.com/package/any-promise) Promises)
154
+
155
+ Also, [`util.promisify`](https://nodejs.org/api/util.html#util_util_promisify_original), 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.
156
+
157
+
158
+ [back to top](#table-of-contents)
159
+
160
+
161
+ ---
162
+
163
+
164
+ ## Forms
165
+
166
+ `request` supports `application/x-www-form-urlencoded` and `multipart/form-data` form uploads. For `multipart/related` refer to the `multipart` API.
167
+
168
+
169
+ #### application/x-www-form-urlencoded (URL-Encoded Forms)
170
+
171
+ URL-encoded forms are simple.
172
+
173
+ ```js
174
+ request.post('http://service.com/upload', {form:{key:'value'}})
175
+ // or
176
+ request.post('http://service.com/upload').form({key:'value'})
177
+ // or
178
+ request.post({url:'http://service.com/upload', form: {key:'value'}}, function(err,httpResponse,body){ /* ... */ })
179
+ ```
180
+
181
+
182
+ #### multipart/form-data (Multipart Form Uploads)
183
+
184
+ For `multipart/form-data` we use the [form-data](https://github.com/form-data/form-data) library by [@felixge](https://github.com/felixge). For the most cases, you can pass your upload form data via the `formData` option.
185
+
186
+
187
+ ```js
188
+ const formData = {
189
+ // Pass a simple key-value pair
190
+ my_field: 'my_value',
191
+ // Pass data via Buffers
192
+ my_buffer: Buffer.from([1, 2, 3]),
193
+ // Pass data via Streams
194
+ my_file: fs.createReadStream(__dirname + '/unicycle.jpg'),
195
+ // Pass multiple values /w an Array
196
+ attachments: [
197
+ fs.createReadStream(__dirname + '/attachment1.jpg'),
198
+ fs.createReadStream(__dirname + '/attachment2.jpg')
199
+ ],
200
+ // Pass optional meta-data with an 'options' object with style: {value: DATA, options: OPTIONS}
201
+ // Use case: for some types of streams, you'll need to provide "file"-related information manually.
202
+ // See the `form-data` README for more information about options: https://github.com/form-data/form-data
203
+ custom_file: {
204
+ value: fs.createReadStream('/dev/urandom'),
205
+ options: {
206
+ filename: 'topsecret.jpg',
207
+ contentType: 'image/jpeg'
208
+ }
209
+ }
210
+ };
211
+ request.post({url:'http://service.com/upload', formData: formData}, function optionalCallback(err, httpResponse, body) {
212
+ if (err) {
213
+ return console.error('upload failed:', err);
214
+ }
215
+ console.log('Upload successful! Server responded with:', body);
216
+ });
217
+ ```
218
+
219
+ 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.)
220
+
221
+ ```js
222
+ // NOTE: Advanced use-case, for normal use see 'formData' usage above
223
+ const r = request.post('http://service.com/upload', function optionalCallback(err, httpResponse, body) {...})
224
+ const form = r.form();
225
+ form.append('my_field', 'my_value');
226
+ form.append('my_buffer', Buffer.from([1, 2, 3]));
227
+ form.append('custom_file', fs.createReadStream(__dirname + '/unicycle.jpg'), {filename: 'unicycle.jpg'});
228
+ ```
229
+ See the [form-data README](https://github.com/form-data/form-data) for more information & examples.
230
+
231
+
232
+ #### multipart/related
233
+
234
+ 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.
235
+
236
+ ```js
237
+ request({
238
+ method: 'PUT',
239
+ preambleCRLF: true,
240
+ postambleCRLF: true,
241
+ uri: 'http://service.com/upload',
242
+ multipart: [
243
+ {
244
+ 'content-type': 'application/json',
245
+ body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}})
246
+ },
247
+ { body: 'I am an attachment' },
248
+ { body: fs.createReadStream('image.png') }
249
+ ],
250
+ // alternatively pass an object containing additional options
251
+ multipart: {
252
+ chunked: false,
253
+ data: [
254
+ {
255
+ 'content-type': 'application/json',
256
+ body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}})
257
+ },
258
+ { body: 'I am an attachment' }
259
+ ]
260
+ }
261
+ },
262
+ function (error, response, body) {
263
+ if (error) {
264
+ return console.error('upload failed:', error);
265
+ }
266
+ console.log('Upload successful! Server responded with:', body);
267
+ })
268
+ ```
269
+
270
+ [back to top](#table-of-contents)
271
+
272
+
273
+ ---
274
+
275
+
276
+ ## HTTP Authentication
277
+
278
+ ```js
279
+ request.get('http://some.server.com/').auth('username', 'password', false);
280
+ // or
281
+ request.get('http://some.server.com/', {
282
+ 'auth': {
283
+ 'user': 'username',
284
+ 'pass': 'password',
285
+ 'sendImmediately': false
286
+ }
287
+ });
288
+ // or
289
+ request.get('http://some.server.com/').auth(null, null, true, 'bearerToken');
290
+ // or
291
+ request.get('http://some.server.com/', {
292
+ 'auth': {
293
+ 'bearer': 'bearerToken'
294
+ }
295
+ });
296
+ ```
297
+
298
+ If passed as an option, `auth` should be a hash containing values:
299
+
300
+ - `user` || `username`
301
+ - `pass` || `password`
302
+ - `sendImmediately` (optional)
303
+ - `bearer` (optional)
304
+
305
+ The method form takes parameters
306
+ `auth(username, password, sendImmediately, bearer)`.
307
+
308
+ `sendImmediately` defaults to `true`, which causes a basic or bearer
309
+ authentication header to be sent. If `sendImmediately` is `false`, then
310
+ `request` will retry with a proper authentication header after receiving a
311
+ `401` response from the server (which must contain a `WWW-Authenticate` header
312
+ indicating the required authentication method).
313
+
314
+ Note that you can also specify basic authentication using the URL itself, as
315
+ detailed in [RFC 1738](http://www.ietf.org/rfc/rfc1738.txt). Simply pass the
316
+ `user:password` before the host with an `@` sign:
317
+
318
+ ```js
319
+ const username = 'username',
320
+ password = 'password',
321
+ url = 'http://' + username + ':' + password + '@some.server.com';
322
+
323
+ request({url}, function (error, response, body) {
324
+ // Do more stuff with 'body' here
325
+ });
326
+ ```
327
+
328
+ Digest authentication is supported, but it only works with `sendImmediately`
329
+ set to `false`; otherwise `request` will send basic authentication on the
330
+ initial request, which will probably cause the request to fail.
331
+
332
+ Bearer authentication is supported, and is activated when the `bearer` value is
333
+ available. The value may be either a `String` or a `Function` returning a
334
+ `String`. Using a function to supply the bearer token is particularly useful if
335
+ used in conjunction with `defaults` to allow a single function to supply the
336
+ last known token at the time of sending a request, or to compute one on the fly.
337
+
338
+ [back to top](#table-of-contents)
339
+
340
+
341
+ ---
342
+
343
+
344
+ ## Custom HTTP Headers
345
+
346
+ HTTP Headers, such as `User-Agent`, can be set in the `options` object.
347
+ In the example below, we call the github API to find out the number
348
+ of stars and forks for the request repository. This requires a
349
+ custom `User-Agent` header as well as https.
350
+
351
+ ```js
352
+ const request = require('request');
353
+
354
+ const options = {
355
+ url: 'https://api.github.com/repos/cypress-io/request',
356
+ headers: {
357
+ 'User-Agent': 'request'
358
+ }
359
+ };
360
+
361
+ function callback(error, response, body) {
362
+ if (!error && response.statusCode == 200) {
363
+ const info = JSON.parse(body);
364
+ console.log(info.stargazers_count + " Stars");
365
+ console.log(info.forks_count + " Forks");
366
+ }
367
+ }
368
+
369
+ request(options, callback);
370
+ ```
371
+
372
+ [back to top](#table-of-contents)
373
+
374
+
375
+ ---
376
+
377
+ ## Proxies
378
+
379
+ If you specify a `proxy` option, then the request (and any subsequent
380
+ redirects) will be sent via a connection to the proxy server.
381
+
382
+ If your endpoint is an `https` url, and you are using a proxy, then
383
+ request will send a `CONNECT` request to the proxy server *first*, and
384
+ then use the supplied connection to connect to the endpoint.
385
+
386
+ That is, first it will make a request like:
387
+
388
+ ```
389
+ HTTP/1.1 CONNECT endpoint-server.com:80
390
+ Host: proxy-server.com
391
+ User-Agent: whatever user agent you specify
392
+ ```
393
+
394
+ and then the proxy server make a TCP connection to `endpoint-server`
395
+ on port `80`, and return a response that looks like:
396
+
397
+ ```
398
+ HTTP/1.1 200 OK
399
+ ```
400
+
401
+ At this point, the connection is left open, and the client is
402
+ communicating directly with the `endpoint-server.com` machine.
403
+
404
+ See [the wikipedia page on HTTP Tunneling](https://en.wikipedia.org/wiki/HTTP_tunnel)
405
+ for more information.
406
+
407
+ By default, when proxying `http` traffic, request will simply make a
408
+ standard proxied `http` request. This is done by making the `url`
409
+ section of the initial line of the request a fully qualified url to
410
+ the endpoint.
411
+
412
+ For example, it will make a single request that looks like:
413
+
414
+ ```
415
+ HTTP/1.1 GET http://endpoint-server.com/some-url
416
+ Host: proxy-server.com
417
+ Other-Headers: all go here
418
+
419
+ request body or whatever
420
+ ```
421
+
422
+ Because a pure "http over http" tunnel offers no additional security
423
+ or other features, it is generally simpler to go with a
424
+ straightforward HTTP proxy in this case. However, if you would like
425
+ to force a tunneling proxy, you may set the `tunnel` option to `true`.
426
+
427
+ You can also make a standard proxied `http` request by explicitly setting
428
+ `tunnel : false`, but **note that this will allow the proxy to see the traffic
429
+ to/from the destination server**.
430
+
431
+ If you are using a tunneling proxy, you may set the
432
+ `proxyHeaderWhiteList` to share certain headers with the proxy.
433
+
434
+ You can also set the `proxyHeaderExclusiveList` to share certain
435
+ headers only with the proxy and not with destination host.
436
+
437
+ By default, this set is:
438
+
439
+ ```
440
+ accept
441
+ accept-charset
442
+ accept-encoding
443
+ accept-language
444
+ accept-ranges
445
+ cache-control
446
+ content-encoding
447
+ content-language
448
+ content-length
449
+ content-location
450
+ content-md5
451
+ content-range
452
+ content-type
453
+ connection
454
+ date
455
+ expect
456
+ max-forwards
457
+ pragma
458
+ proxy-authorization
459
+ referer
460
+ te
461
+ transfer-encoding
462
+ user-agent
463
+ via
464
+ ```
465
+
466
+ Note that, when using a tunneling proxy, the `proxy-authorization`
467
+ header and any headers from custom `proxyHeaderExclusiveList` are
468
+ *never* sent to the endpoint server, but only to the proxy server.
469
+
470
+
471
+ ### Controlling proxy behaviour using environment variables
472
+
473
+ The following environment variables are respected by `request`:
474
+
475
+ * `HTTP_PROXY` / `http_proxy`
476
+ * `HTTPS_PROXY` / `https_proxy`
477
+ * `NO_PROXY` / `no_proxy`
478
+
479
+ 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.
480
+
481
+ `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.
482
+
483
+ Here's some examples of valid `no_proxy` values:
484
+
485
+ * `google.com` - don't proxy HTTP/HTTPS requests to Google.
486
+ * `google.com:443` - don't proxy HTTPS requests to Google, but *do* proxy HTTP requests to Google.
487
+ * `google.com:443, yahoo.com:80` - don't proxy HTTPS requests to Google, and don't proxy HTTP requests to Yahoo!
488
+ * `*` - ignore `https_proxy`/`http_proxy` environment variables altogether.
489
+
490
+ [back to top](#table-of-contents)
491
+
492
+
493
+ ---
494
+
495
+
496
+ ## UNIX Domain Sockets
497
+
498
+ `request` supports making requests to [UNIX Domain Sockets](https://en.wikipedia.org/wiki/Unix_domain_socket). To make one, use the following URL scheme:
499
+
500
+ ```js
501
+ /* Pattern */ 'http://unix:SOCKET:PATH'
502
+ /* Example */ request.get('http://unix:/absolute/path/to/unix.socket:/request/path')
503
+ ```
504
+
505
+ Note: The `SOCKET` path is assumed to be absolute to the root of the host file system.
506
+
507
+ [back to top](#table-of-contents)
508
+
509
+
510
+ ---
511
+
512
+
513
+ ## TLS/SSL Protocol
514
+
515
+ TLS/SSL Protocol options, such as `cert`, `key` and `passphrase`, can be
516
+ 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).
517
+
518
+ ```js
519
+ const fs = require('fs')
520
+ , path = require('path')
521
+ , certFile = path.resolve(__dirname, 'ssl/client.crt')
522
+ , keyFile = path.resolve(__dirname, 'ssl/client.key')
523
+ , caFile = path.resolve(__dirname, 'ssl/ca.cert.pem')
524
+ , request = require('request');
525
+
526
+ const options = {
527
+ url: 'https://api.some-server.com/',
528
+ cert: fs.readFileSync(certFile),
529
+ key: fs.readFileSync(keyFile),
530
+ passphrase: 'password',
531
+ ca: fs.readFileSync(caFile)
532
+ };
533
+
534
+ request.get(options);
535
+ ```
536
+
537
+ ### Using `options.agentOptions`
538
+
539
+ In the example below, we call an API that requires client side SSL certificate
540
+ (in PEM format) with passphrase protected private key (in PEM format) and disable the SSLv3 protocol:
541
+
542
+ ```js
543
+ const fs = require('fs')
544
+ , path = require('path')
545
+ , certFile = path.resolve(__dirname, 'ssl/client.crt')
546
+ , keyFile = path.resolve(__dirname, 'ssl/client.key')
547
+ , request = require('request');
548
+
549
+ const options = {
550
+ url: 'https://api.some-server.com/',
551
+ agentOptions: {
552
+ cert: fs.readFileSync(certFile),
553
+ key: fs.readFileSync(keyFile),
554
+ // Or use `pfx` property replacing `cert` and `key` when using private key, certificate and CA certs in PFX or PKCS12 format:
555
+ // pfx: fs.readFileSync(pfxFilePath),
556
+ passphrase: 'password',
557
+ securityOptions: 'SSL_OP_NO_SSLv3'
558
+ }
559
+ };
560
+
561
+ request.get(options);
562
+ ```
563
+
564
+ It is able to force using SSLv3 only by specifying `secureProtocol`:
565
+
566
+ ```js
567
+ request.get({
568
+ url: 'https://api.some-server.com/',
569
+ agentOptions: {
570
+ secureProtocol: 'SSLv3_method'
571
+ }
572
+ });
573
+ ```
574
+
575
+ It is possible to accept other certificates than those signed by generally allowed Certificate Authorities (CAs).
576
+ This can be useful, for example, when using self-signed certificates.
577
+ 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`.
578
+ The certificate the domain presents must be signed by the root certificate specified:
579
+
580
+ ```js
581
+ request.get({
582
+ url: 'https://api.some-server.com/',
583
+ agentOptions: {
584
+ ca: fs.readFileSync('ca.cert.pem')
585
+ }
586
+ });
587
+ ```
588
+
589
+ 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:
590
+ 1. its own public key, which is signed by:
591
+ 2. an intermediate "Corp Issuing Server", that is in turn signed by:
592
+ 3. a root CA "Corp Root CA";
593
+
594
+ you can configure your request as follows:
595
+
596
+ ```js
597
+ request.get({
598
+ url: 'https://api.some-server.com/',
599
+ agentOptions: {
600
+ ca: [
601
+ fs.readFileSync('Corp Issuing Server.pem'),
602
+ fs.readFileSync('Corp Root CA.pem')
603
+ ]
604
+ }
605
+ });
606
+ ```
607
+
608
+ [back to top](#table-of-contents)
609
+
610
+
611
+ ---
612
+
613
+ ## Support for HAR 1.2
614
+
615
+ 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`.
616
+
617
+ A validation step will check if the HAR Request format matches the latest spec (v1.2) and will skip parsing if not matching.
618
+
619
+ ```js
620
+ const request = require('request')
621
+ request({
622
+ // will be ignored
623
+ method: 'GET',
624
+ uri: 'http://www.google.com',
625
+
626
+ // HTTP Archive Request Object
627
+ har: {
628
+ url: 'http://www.mockbin.com/har',
629
+ method: 'POST',
630
+ headers: [
631
+ {
632
+ name: 'content-type',
633
+ value: 'application/x-www-form-urlencoded'
634
+ }
635
+ ],
636
+ postData: {
637
+ mimeType: 'application/x-www-form-urlencoded',
638
+ params: [
639
+ {
640
+ name: 'foo',
641
+ value: 'bar'
642
+ },
643
+ {
644
+ name: 'hello',
645
+ value: 'world'
646
+ }
647
+ ]
648
+ }
649
+ }
650
+ })
651
+
652
+ // a POST request will be sent to http://www.mockbin.com
653
+ // with body an application/x-www-form-urlencoded body:
654
+ // foo=bar&hello=world
655
+ ```
656
+
657
+ [back to top](#table-of-contents)
658
+
659
+
660
+ ---
661
+
662
+ ## request(options, callback)
663
+
664
+ The first argument can be either a `url` or an `options` object. The only required option is `uri`; all others are optional.
665
+
666
+ - `uri` || `url` - fully qualified uri or a parsed url object from `url.parse()`
667
+ - `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.
668
+ - `method` - http method (default: `"GET"`)
669
+ - `headers` - http headers (default: `{}`)
670
+
671
+ ---
672
+
673
+ - `qs` - object containing querystring values to be appended to the `uri`
674
+ - `qsParseOptions` - object containing options to pass to the [qs.parse](https://github.com/hapijs/qs#parsing-objects) method. Alternatively pass options to the [querystring.parse](https://nodejs.org/docs/v0.12.0/api/querystring.html#querystring_querystring_parse_str_sep_eq_options) method using this format `{sep:';', eq:':', options:{}}`
675
+ - `qsStringifyOptions` - object containing options to pass to the [qs.stringify](https://github.com/hapijs/qs#stringifying) method. Alternatively pass options to the [querystring.stringify](https://nodejs.org/docs/v0.12.0/api/querystring.html#querystring_querystring_stringify_obj_sep_eq_options) 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`
676
+ - `useQuerystring` - if true, use `querystring` to stringify and parse
677
+ querystrings, otherwise use `qs` (default: `false`). Set this option to
678
+ `true` if you need arrays to be serialized as `foo=bar&foo=baz` instead of the
679
+ default `foo[0]=bar&foo[1]=baz`.
680
+
681
+ ---
682
+
683
+ - `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.
684
+ - `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.
685
+ - `formData` - data to pass for a `multipart/form-data` request. See
686
+ [Forms](#forms) section above.
687
+ - `multipart` - array of objects which contain their own headers and `body`
688
+ attributes. Sends a `multipart/related` request. See [Forms](#forms) section
689
+ above.
690
+ - Alternatively you can pass in an object `{chunked: false, data: []}` where
691
+ `chunked` is used to specify whether the request is sent in
692
+ [chunked transfer encoding](https://en.wikipedia.org/wiki/Chunked_transfer_encoding)
693
+ In non-chunked requests, data items with body streams are not allowed.
694
+ - `preambleCRLF` - append a newline/CRLF before the boundary of your `multipart/form-data` request.
695
+ - `postambleCRLF` - append a newline/CRLF at the end of the boundary of your `multipart/form-data` request.
696
+ - `json` - sets `body` to JSON representation of value and adds `Content-type: application/json` header. Additionally, parses the response body as JSON.
697
+ - `jsonReviver` - a [reviver function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) that will be passed to `JSON.parse()` when parsing a JSON response body.
698
+ - `jsonReplacer` - a [replacer function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) that will be passed to `JSON.stringify()` when stringifying a JSON request body.
699
+
700
+ ---
701
+
702
+ - `auth` - a hash containing values `user` || `username`, `pass` || `password`, and `sendImmediately` (optional). See documentation above.
703
+ - `hawk` - options for [Hawk signing](https://github.com/hueniverse/hawk). The `credentials` key must contain the necessary signing info, [see hawk docs for details](https://github.com/hueniverse/hawk#usage-example).
704
+ - `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.
705
+ - `httpSignature` - options for the [HTTP Signature Scheme](https://github.com/joyent/node-http-signature/blob/master/http_signing.md) using [Joyent's library](https://github.com/joyent/node-http-signature). The `keyId` and `key` properties must be specified. See the docs for other options.
706
+
707
+ ---
708
+
709
+ - `followRedirect` - follow HTTP 3xx responses as redirects (default: `true`). This property can also be implemented as function which gets `response` object as the first argument.
710
+ - *(synchronous usage)* It should return `true` if redirects should continue or `false` otherwise. If it returns a url string, the destination of the redirect will be overridden.
711
+ - *(async callback usage)* If the function has two arguments, it will be treated as an asynchronous function and will be passed a callback as the second argument. Invoke the callback with an error (`null` if no error) and the boolean/url result as the second.
712
+ - *(async promise usage)* Return a promise that resolves to the boolean/url result.
713
+ - `followAllRedirects` - follow non-GET HTTP 3xx responses as redirects (default: `false`)
714
+ - `followOriginalHttpMethod` - by default we redirect to HTTP method GET. you can enable this property to redirect to the original HTTP method (default: `false`)
715
+ - `maxRedirects` - the maximum number of redirects to follow (default: `10`)
716
+ - `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.
717
+
718
+ ---
719
+
720
+ - `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](http://nodejs.org/api/buffer.html#buffer_buffer) parameter to `toString()` (meaning this is effectively `utf8` by default). (**Note:** if you expect binary data, you should set `encoding: null`.)
721
+ - `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.
722
+ - `jar` - if `true`, remember cookies for future use (or define your custom cookie jar; see examples section)
723
+
724
+ ---
725
+
726
+ - `agent` - `http(s).Agent` instance to use
727
+ - `agentClass` - alternatively specify your agent's class name
728
+ - `agentOptions` - and pass its options. **Note:** for HTTPS see [tls API doc for TLS/SSL options](http://nodejs.org/api/tls.html#tls_tls_connect_options_callback) and the [documentation above](#using-optionsagentoptions).
729
+ - `forever` - set to `true` to use the [forever-agent](https://github.com/request/forever-agent) **Note:** Defaults to `http(s).Agent({keepAlive:true})` in node 0.12+
730
+ - `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.
731
+ - 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}`).
732
+ - Note that if you are sending multiple requests in a loop and creating
733
+ multiple new `pool` objects, `maxSockets` will not work as intended. To
734
+ work around this, either use [`request.defaults`](#requestdefaultsoptions)
735
+ with your pool options or create the pool object with the `maxSockets`
736
+ property outside of the loop.
737
+ - `timeout` - integer containing number of milliseconds, controls two timeouts.
738
+ - **Read timeout**: Time to wait for a server to send response headers (and start the response body) before aborting the request.
739
+ - **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][linux-timeout])
740
+
741
+ [linux-timeout]: http://www.sekuda.com/overriding_the_default_linux_kernel_20_second_tcp_socket_connect_timeout
742
+
743
+ ---
744
+
745
+ - `localAddress` - local interface to bind for network connections.
746
+ - `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`)
747
+ - `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.
748
+ - `tunnel` - controls the behavior of
749
+ [HTTP `CONNECT` tunneling](https://en.wikipedia.org/wiki/HTTP_tunnel#HTTP_CONNECT_tunneling)
750
+ as follows:
751
+ - `undefined` (default) - `true` if the destination is `https`, `false` otherwise
752
+ - `true` - always tunnel to the destination by making a `CONNECT` request to
753
+ the proxy
754
+ - `false` - request the destination as a `GET` request.
755
+ - `proxyHeaderWhiteList` - a whitelist of headers to send to a
756
+ tunneling proxy.
757
+ - `proxyHeaderExclusiveList` - a whitelist of headers to send
758
+ exclusively to a tunneling proxy and not to destination.
759
+
760
+ ---
761
+
762
+ - `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:
763
+ - `elapsedTime` Duration of the entire request/response in milliseconds (*deprecated*).
764
+ - `responseStartTime` Timestamp when the response began (in Unix Epoch milliseconds) (*deprecated*).
765
+ - `timingStart` Timestamp of the start of the request (in Unix Epoch milliseconds).
766
+ - `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:
767
+ - `socket` Relative timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_socket) module's `socket` event fires. This happens when the socket is assigned to the request.
768
+ - `lookup` Relative timestamp when the [`net`](https://nodejs.org/api/net.html#net_event_lookup) module's `lookup` event fires. This happens when the DNS has been resolved.
769
+ - `connect`: Relative timestamp when the [`net`](https://nodejs.org/api/net.html#net_event_connect) module's `connect` event fires. This happens when the server acknowledges the TCP connection.
770
+ - `response`: Relative timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_response) module's `response` event fires. This happens when the first bytes are received from the server.
771
+ - `end`: Relative timestamp when the last bytes of the response are received.
772
+ - `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:
773
+ - `wait`: Duration of socket initialization (`timings.socket`)
774
+ - `dns`: Duration of DNS lookup (`timings.lookup` - `timings.socket`)
775
+ - `tcp`: Duration of TCP connection (`timings.connect` - `timings.socket`)
776
+ - `firstByte`: Duration of HTTP server response (`timings.response` - `timings.connect`)
777
+ - `download`: Duration of HTTP download (`timings.end` - `timings.response`)
778
+ - `total`: Duration entire HTTP round-trip (`timings.end`)
779
+
780
+ - `har` - a [HAR 1.2 Request Object](http://www.softwareishard.com/blog/har-12-spec/#request), will be processed from HAR format into options overwriting matching values *(see the [HAR 1.2 section](#support-for-har-12) for details)*
781
+ - `callback` - alternatively pass the request's callback in the options object
782
+
783
+ The callback argument gets 3 arguments:
784
+
785
+ 1. An `error` when applicable (usually from [`http.ClientRequest`](http://nodejs.org/api/http.html#http_class_http_clientrequest) object)
786
+ 2. An [`http.IncomingMessage`](https://nodejs.org/api/http.html#http_class_http_incomingmessage) object (Response object)
787
+ 3. The third is the `response` body (`String` or `Buffer`, or JSON object if the `json` option is supplied)
788
+
789
+ [back to top](#table-of-contents)
790
+
791
+
792
+ ---
793
+
794
+ ## Convenience methods
795
+
796
+ There are also shorthand methods for different HTTP METHODs and some other conveniences.
797
+
798
+
799
+ ### request.defaults(options)
800
+
801
+ This method **returns a wrapper** around the normal request API that defaults
802
+ to whatever options you pass to it.
803
+
804
+ **Note:** `request.defaults()` **does not** modify the global request API;
805
+ instead, it **returns a wrapper** that has your default settings applied to it.
806
+
807
+ **Note:** You can call `.defaults()` on the wrapper that is returned from
808
+ `request.defaults` to add/override defaults that were previously defaulted.
809
+
810
+ For example:
811
+ ```js
812
+ //requests using baseRequest() will set the 'x-token' header
813
+ const baseRequest = request.defaults({
814
+ headers: {'x-token': 'my-token'}
815
+ })
816
+
817
+ //requests using specialRequest() will include the 'x-token' header set in
818
+ //baseRequest and will also include the 'special' header
819
+ const specialRequest = baseRequest.defaults({
820
+ headers: {special: 'special value'}
821
+ })
822
+ ```
823
+
824
+ ### request.METHOD()
825
+
826
+ These HTTP method convenience functions act just like `request()` but with a default method already set for you:
827
+
828
+ - *request.get()*: Defaults to `method: "GET"`.
829
+ - *request.post()*: Defaults to `method: "POST"`.
830
+ - *request.put()*: Defaults to `method: "PUT"`.
831
+ - *request.patch()*: Defaults to `method: "PATCH"`.
832
+ - *request.del() / request.delete()*: Defaults to `method: "DELETE"`.
833
+ - *request.head()*: Defaults to `method: "HEAD"`.
834
+ - *request.options()*: Defaults to `method: "OPTIONS"`.
835
+
836
+ ### request.cookie()
837
+
838
+ Function that creates a new cookie.
839
+
840
+ ```js
841
+ request.cookie('key1=value1')
842
+ ```
843
+ ### request.jar()
844
+
845
+ Function that creates a new cookie jar.
846
+
847
+ ```js
848
+ request.jar()
849
+ ```
850
+
851
+ ### response.caseless.get('header-name')
852
+
853
+ Function that returns the specified response header field using a [case-insensitive match](https://tools.ietf.org/html/rfc7230#section-3.2)
854
+
855
+ ```js
856
+ request('http://www.google.com', function (error, response, body) {
857
+ // print the Content-Type header even if the server returned it as 'content-type' (lowercase)
858
+ console.log('Content-Type is:', response.caseless.get('Content-Type'));
859
+ });
860
+ ```
861
+
862
+ [back to top](#table-of-contents)
863
+
864
+
865
+ ---
866
+
867
+
868
+ ## Debugging
869
+
870
+ There are at least three ways to debug the operation of `request`:
871
+
872
+ 1. Launch the node process like `NODE_DEBUG=request node script.js`
873
+ (`lib,request,otherlib` works too).
874
+
875
+ 2. Set `require('request').debug = true` at any time (this does the same thing
876
+ as #1).
877
+
878
+ 3. Use the [request-debug module](https://github.com/cypress-io/request-debug) to
879
+ view request and response headers and bodies.
880
+
881
+ [back to top](#table-of-contents)
882
+
883
+
884
+ ---
885
+
886
+ ## Timeouts
887
+
888
+ Most requests to external servers should have a timeout attached, in case the
889
+ server is not responding in a timely manner. Without a timeout, your code may
890
+ have a socket open/consume resources for minutes or more.
891
+
892
+ There are two main types of timeouts: **connection timeouts** and **read
893
+ timeouts**. A connect timeout occurs if the timeout is hit while your client is
894
+ attempting to establish a connection to a remote machine (corresponding to the
895
+ [connect() call][connect] on the socket). A read timeout occurs any time the
896
+ server is too slow to send back a part of the response.
897
+
898
+ These two situations have widely different implications for what went wrong
899
+ with the request, so it's useful to be able to distinguish them. You can detect
900
+ timeout errors by checking `err.code` for an 'ETIMEDOUT' value. Further, you
901
+ can detect whether the timeout was a connection timeout by checking if the
902
+ `err.connect` property is set to `true`.
903
+
904
+ ```js
905
+ request.get('http://10.255.255.1', {timeout: 1500}, function(err) {
906
+ console.log(err.code === 'ETIMEDOUT');
907
+ // Set to `true` if the timeout was a connection timeout, `false` or
908
+ // `undefined` otherwise.
909
+ console.log(err.connect === true);
910
+ process.exit(0);
911
+ });
912
+ ```
913
+
914
+ [connect]: http://linux.die.net/man/2/connect
915
+
916
+ ## Examples:
917
+
918
+ ```js
919
+ const request = require('request')
920
+ , rand = Math.floor(Math.random()*100000000).toString()
921
+ ;
922
+ request(
923
+ { method: 'PUT'
924
+ , uri: 'http://mikeal.iriscouch.com/testjs/' + rand
925
+ , multipart:
926
+ [ { 'content-type': 'application/json'
927
+ , body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}})
928
+ }
929
+ , { body: 'I am an attachment' }
930
+ ]
931
+ }
932
+ , function (error, response, body) {
933
+ if(response.statusCode == 201){
934
+ console.log('document saved as: http://mikeal.iriscouch.com/testjs/'+ rand)
935
+ } else {
936
+ console.log('error: '+ response.statusCode)
937
+ console.log(body)
938
+ }
939
+ }
940
+ )
941
+ ```
942
+
943
+ For backwards-compatibility, response compression is not supported by default.
944
+ To accept gzip-compressed responses, set the `gzip` option to `true`. Note
945
+ that the body data passed through `request` is automatically decompressed
946
+ while the response object is unmodified and will contain compressed data if
947
+ the server sent a compressed response.
948
+
949
+ ```js
950
+ const request = require('request')
951
+ request(
952
+ { method: 'GET'
953
+ , uri: 'http://www.google.com'
954
+ , gzip: true
955
+ }
956
+ , function (error, response, body) {
957
+ // body is the decompressed response body
958
+ console.log('server encoded the data as: ' + (response.headers['content-encoding'] || 'identity'))
959
+ console.log('the decoded data is: ' + body)
960
+ }
961
+ )
962
+ .on('data', function(data) {
963
+ // decompressed data as it is received
964
+ console.log('decoded chunk: ' + data)
965
+ })
966
+ .on('response', function(response) {
967
+ // unmodified http.IncomingMessage object
968
+ response.on('data', function(data) {
969
+ // compressed data as it is received
970
+ console.log('received ' + data.length + ' bytes of compressed data')
971
+ })
972
+ })
973
+ ```
974
+
975
+ 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`).
976
+
977
+ ```js
978
+ const request = request.defaults({jar: true})
979
+ request('http://www.google.com', function () {
980
+ request('http://images.google.com')
981
+ })
982
+ ```
983
+
984
+ 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`)
985
+
986
+ ```js
987
+ const j = request.jar()
988
+ const request = request.defaults({jar:j})
989
+ request('http://www.google.com', function () {
990
+ request('http://images.google.com')
991
+ })
992
+ ```
993
+
994
+ OR
995
+
996
+ ```js
997
+ const j = request.jar();
998
+ const cookie = request.cookie('key1=value1');
999
+ const url = 'http://www.google.com';
1000
+ j.setCookie(cookie, url);
1001
+ request({url: url, jar: j}, function () {
1002
+ request('http://images.google.com')
1003
+ })
1004
+ ```
1005
+
1006
+ To use a custom cookie store (such as a
1007
+ [`FileCookieStore`](https://github.com/mitsuru/tough-cookie-filestore)
1008
+ which supports saving to and restoring from JSON files), pass it as a parameter
1009
+ to `request.jar()`:
1010
+
1011
+ ```js
1012
+ const FileCookieStore = require('tough-cookie-filestore');
1013
+ // NOTE - currently the 'cookies.json' file must already exist!
1014
+ const j = request.jar(new FileCookieStore('cookies.json'));
1015
+ request = request.defaults({ jar : j })
1016
+ request('http://www.google.com', function() {
1017
+ request('http://images.google.com')
1018
+ })
1019
+ ```
1020
+
1021
+ The cookie store must be a
1022
+ [`tough-cookie`](https://github.com/SalesforceEng/tough-cookie)
1023
+ store and it must support synchronous operations; see the
1024
+ [`CookieStore` API docs](https://github.com/SalesforceEng/tough-cookie#api)
1025
+ for details.
1026
+
1027
+ To inspect your cookie jar after a request:
1028
+
1029
+ ```js
1030
+ const j = request.jar()
1031
+ request({url: 'http://www.google.com', jar: j}, function () {
1032
+ const cookie_string = j.getCookieString(url); // "key1=value1; key2=value2; ..."
1033
+ const cookies = j.getCookies(url);
1034
+ // [{key: 'key1', value: 'value1', domain: "www.google.com", ...}, ...]
1035
+ })
1036
+ ```
1037
+
1038
+ [back to top](#table-of-contents)