-
-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy path11-get-info.js
34 lines (28 loc) · 852 Bytes
/
11-get-info.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* Copyright (c) Jonathan Cardoso Machado. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* Example that shows all information you can get from a single request.
*/
const { Curl } = require('../dist')
const curl = new Curl()
const url = 'http://httpbin.org/cookies/set/cookie1name/cookie1value'
curl.setOpt(Curl.option.URL, url)
curl.setOpt(Curl.option.FOLLOWLOCATION, true)
curl.setOpt(Curl.option.COOKIEFILE, '')
curl.perform()
curl.on('end', () => {
for (const infoName in Curl.info) {
if (
Object.prototype.hasOwnProperty.call(Curl.info, infoName) &&
infoName !== 'debug'
) {
console.info(infoName, ': ', curl.getInfo(infoName))
}
}
curl.close()
})
curl.on('error', curl.close.bind(curl))