@readme/httpsnippet 2.4.5 → 3.0.1

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 (69) hide show
  1. package/README.md +19 -9
  2. package/package.json +24 -27
  3. package/src/helpers/code-builder.js +85 -80
  4. package/src/helpers/form-data.js +28 -26
  5. package/src/helpers/headers.js +18 -8
  6. package/src/helpers/reducer.js +10 -14
  7. package/src/index.js +175 -151
  8. package/src/targets/c/index.js +3 -5
  9. package/src/targets/c/libcurl.js +20 -25
  10. package/src/targets/clojure/clj_http.js +126 -102
  11. package/src/targets/clojure/index.js +3 -5
  12. package/src/targets/csharp/httpclient.js +93 -90
  13. package/src/targets/csharp/index.js +3 -5
  14. package/src/targets/csharp/restsharp.js +20 -22
  15. package/src/targets/go/index.js +3 -5
  16. package/src/targets/go/native.js +47 -54
  17. package/src/targets/http/http1.1.js +27 -37
  18. package/src/targets/http/index.js +3 -5
  19. package/src/targets/index.js +2 -4
  20. package/src/targets/java/asynchttp.js +22 -23
  21. package/src/targets/java/index.js +3 -5
  22. package/src/targets/java/nethttp.js +20 -24
  23. package/src/targets/java/okhttp.js +31 -31
  24. package/src/targets/java/unirest.js +22 -19
  25. package/src/targets/javascript/axios.js +47 -42
  26. package/src/targets/javascript/fetch.js +66 -68
  27. package/src/targets/javascript/index.js +3 -5
  28. package/src/targets/javascript/jquery.js +50 -44
  29. package/src/targets/javascript/xhr.js +48 -44
  30. package/src/targets/kotlin/index.js +3 -5
  31. package/src/targets/kotlin/okhttp.js +31 -31
  32. package/src/targets/node/axios.js +37 -34
  33. package/src/targets/node/fetch.js +94 -87
  34. package/src/targets/node/index.js +4 -5
  35. package/src/targets/node/native.js +51 -45
  36. package/src/targets/node/request.js +69 -69
  37. package/src/targets/node/unirest.js +70 -68
  38. package/src/targets/objc/helpers.js +32 -25
  39. package/src/targets/objc/index.js +3 -5
  40. package/src/targets/objc/nsurlsession.js +108 -79
  41. package/src/targets/ocaml/cohttp.js +32 -30
  42. package/src/targets/ocaml/index.js +3 -5
  43. package/src/targets/php/curl.js +86 -82
  44. package/src/targets/php/guzzle.js +135 -0
  45. package/src/targets/php/helpers.js +31 -29
  46. package/src/targets/php/http1.js +38 -49
  47. package/src/targets/php/http2.js +75 -75
  48. package/src/targets/php/index.js +5 -5
  49. package/src/targets/powershell/common.js +35 -30
  50. package/src/targets/powershell/index.js +3 -5
  51. package/src/targets/powershell/restmethod.js +3 -5
  52. package/src/targets/powershell/webrequest.js +3 -5
  53. package/src/targets/python/helpers.js +42 -37
  54. package/src/targets/python/index.js +4 -5
  55. package/src/targets/python/python3.js +33 -45
  56. package/src/targets/python/requests.js +48 -72
  57. package/src/targets/r/httr.js +60 -73
  58. package/src/targets/r/index.js +3 -5
  59. package/src/targets/ruby/index.js +3 -5
  60. package/src/targets/ruby/native.js +41 -35
  61. package/src/targets/shell/curl.js +108 -43
  62. package/src/{helpers/shell.js → targets/shell/helpers.js} +7 -9
  63. package/src/targets/shell/httpie.js +45 -39
  64. package/src/targets/shell/index.js +4 -5
  65. package/src/targets/shell/wget.js +20 -22
  66. package/src/targets/swift/helpers.js +44 -35
  67. package/src/targets/swift/index.js +3 -5
  68. package/src/targets/swift/nsurlsession.js +93 -79
  69. package/src/.DS_Store +0 -0
package/src/index.js CHANGED
@@ -1,106 +1,113 @@
1
- /* eslint-env browser */
1
+ const es = require('event-stream');
2
+ const MultiPartForm = require('form-data');
3
+ const qs = require('qs');
4
+ const reducer = require('./helpers/reducer');
5
+ const helpers = require('./helpers/headers');
6
+ const targets = require('./targets');
7
+ const url = require('url');
8
+ const validate = require('har-validator/lib/async');
2
9
 
3
- 'use strict'
4
-
5
- var es = require('event-stream')
6
- var MultiPartForm = require('form-data')
7
- var qs = require('qs')
8
- var reducer = require('./helpers/reducer')
9
- var helpers = require('./helpers/headers')
10
- var targets = require('./targets')
11
- var url = require('url')
12
- var validate = require('har-validator/lib/async')
13
-
14
- const { formDataIterator, isBlob } = require('./helpers/form-data.js')
10
+ const { formDataIterator, isBlob } = require('./helpers/form-data');
15
11
 
16
12
  // constructor
17
- var HTTPSnippet = function (data, opts = {}) {
18
- var entries
19
- var self = this
20
- var input = Object.assign({}, data)
13
+ const HTTPSnippet = function (data, opts = {}) {
14
+ let entries;
15
+ const self = this;
16
+ const input = { ...data };
21
17
 
22
- var options = Object.assign({
23
- escapeQueryStrings: true
24
- }, opts)
18
+ const options = {
19
+ harIsAlreadyEncoded: false,
20
+ ...opts,
21
+ };
25
22
 
26
23
  // prep the main container
27
- self.requests = []
24
+ self.requests = [];
28
25
 
29
26
  // is it har?
30
27
  if (input.log && input.log.entries) {
31
- entries = input.log.entries
28
+ entries = input.log.entries;
32
29
  } else {
33
- entries = [{
34
- request: input
35
- }]
30
+ entries = [
31
+ {
32
+ request: input,
33
+ },
34
+ ];
36
35
  }
37
36
 
38
37
  entries.forEach(function (entry) {
38
+ const request = { ...entry.request };
39
+
39
40
  // add optional properties to make validation successful
40
- entry.request.httpVersion = entry.request.httpVersion || 'HTTP/1.1'
41
- entry.request.queryString = entry.request.queryString || []
42
- entry.request.headers = entry.request.headers || []
43
- entry.request.cookies = entry.request.cookies || []
44
- entry.request.postData = entry.request.postData || {}
45
- entry.request.postData.mimeType = entry.request.postData.mimeType || 'application/octet-stream'
46
-
47
- entry.request.bodySize = 0
48
- entry.request.headersSize = 0
49
- entry.request.postData.size = 0
50
-
51
- validate.request(entry.request, function (err, valid) {
41
+ request.httpVersion = request.httpVersion || 'HTTP/1.1';
42
+ request.queryString = request.queryString || [];
43
+ request.headers = request.headers || [];
44
+ request.cookies = request.cookies || [];
45
+ request.postData = request.postData || {};
46
+ request.postData.mimeType = request.postData.mimeType || 'application/octet-stream';
47
+
48
+ request.bodySize = 0;
49
+ request.headersSize = 0;
50
+ request.postData.size = 0;
51
+
52
+ validate.request(request, function (err, valid) {
52
53
  if (!valid) {
53
- throw err
54
+ throw err;
54
55
  }
55
56
 
56
- self.requests.push(self.prepare(entry.request, options))
57
- })
58
- })
59
- }
57
+ self.requests.push(self.prepare(request, options));
58
+ });
59
+ });
60
+ };
60
61
 
61
62
  HTTPSnippet.prototype.prepare = function (request, options) {
62
63
  // construct utility properties
63
- request.queryObj = {}
64
- request.headersObj = {}
65
- request.cookiesObj = {}
66
- request.allHeaders = {}
67
- request.postData.jsonObj = false
68
- request.postData.paramsObj = false
64
+ request.queryObj = {};
65
+ request.headersObj = {};
66
+ request.cookiesObj = {};
67
+ request.allHeaders = {};
68
+ request.postData.jsonObj = false;
69
+ request.postData.paramsObj = false;
69
70
 
70
71
  // construct query objects
71
72
  if (request.queryString && request.queryString.length) {
72
- request.queryObj = request.queryString.reduce(reducer, {})
73
+ request.queryObj = request.queryString.reduce(reducer, {});
73
74
  }
74
75
 
75
76
  // construct headers objects
76
77
  if (request.headers && request.headers.length) {
77
- var http2VersionRegex = /^HTTP\/2/
78
+ const http2VersionRegex = /^HTTP\/2/;
78
79
  request.headersObj = request.headers.reduce(function (headers, header) {
79
- var headerName = header.name
80
+ let headerName = header.name;
80
81
  if (request.httpVersion.match(http2VersionRegex)) {
81
- headerName = headerName.toLowerCase()
82
+ headerName = headerName.toLowerCase();
82
83
  }
83
84
 
84
- headers[headerName] = header.value
85
- return headers
86
- }, {})
85
+ // eslint-disable-next-line no-param-reassign
86
+ headers[headerName] = header.value;
87
+ return headers;
88
+ }, {});
87
89
  }
88
90
 
89
91
  // construct headers objects
90
92
  if (request.cookies && request.cookies.length) {
91
93
  request.cookiesObj = request.cookies.reduceRight(function (cookies, cookie) {
92
- cookies[cookie.name] = cookie.value
93
- return cookies
94
- }, {})
94
+ // eslint-disable-next-line no-param-reassign
95
+ cookies[cookie.name] = cookie.value;
96
+ return cookies;
97
+ }, {});
95
98
  }
96
99
 
97
100
  // construct Cookie header
98
- var cookies = request.cookies.map(function (cookie) {
99
- return encodeURIComponent(cookie.name) + '=' + encodeURIComponent(cookie.value)
100
- })
101
+ const cookies = request.cookies.map(function (cookie) {
102
+ if (options.harIsAlreadyEncoded) {
103
+ return `${cookie.name}=${cookie.value}`;
104
+ }
105
+
106
+ return `${encodeURIComponent(cookie.name)}=${encodeURIComponent(cookie.value)}`;
107
+ });
101
108
 
102
109
  if (cookies.length) {
103
- request.allHeaders.cookie = cookies.join('; ')
110
+ request.allHeaders.cookie = cookies.join('; ');
104
111
  }
105
112
 
106
113
  switch (request.postData.mimeType) {
@@ -109,11 +116,11 @@ HTTPSnippet.prototype.prepare = function (request, options) {
109
116
  case 'multipart/form-data':
110
117
  case 'multipart/alternative':
111
118
  // reset values
112
- request.postData.text = ''
113
- request.postData.mimeType = 'multipart/form-data'
119
+ request.postData.text = '';
120
+ request.postData.mimeType = 'multipart/form-data';
114
121
 
115
122
  if (request.postData.params) {
116
- var form = new MultiPartForm()
123
+ const form = new MultiPartForm();
117
124
 
118
125
  // The `form-data` module returns one of two things: a native FormData object, or its own polyfill. Since the
119
126
  // polyfill does not support the full API of the native FormData object, when this library is running in a
@@ -129,209 +136,226 @@ HTTPSnippet.prototype.prepare = function (request, options) {
129
136
  // This hack is pretty awful but it's the only way we can use this library in the browser as if we code this
130
137
  // against just the native FormData object, we can't polyfill that back into Node because Blob and File objects,
131
138
  // which something like `formdata-polyfill` requires, don't exist there.
132
- const isNativeFormData = (typeof form[Symbol.iterator] === 'function')
139
+ const isNativeFormData = typeof form[Symbol.iterator] === 'function';
133
140
 
134
141
  // easter egg
135
- const boundary = '---011000010111000001101001'
142
+ const boundary = '---011000010111000001101001';
136
143
  if (!isNativeFormData) {
137
- form._boundary = boundary
144
+ form._boundary = boundary;
138
145
  }
139
146
 
140
147
  request.postData.params.forEach(function (param) {
141
- const name = param.name
142
- const value = param.value || ''
143
- const filename = param.fileName || null
148
+ const name = param.name;
149
+ const value = param.value || '';
150
+ const filename = param.fileName || null;
144
151
 
145
152
  if (isNativeFormData) {
146
153
  if (isBlob(value)) {
147
- form.append(name, value, filename)
154
+ form.append(name, value, filename);
148
155
  } else {
149
- form.append(name, value)
156
+ form.append(name, value);
150
157
  }
151
158
  } else {
152
159
  form.append(name, value, {
153
160
  filename: filename,
154
- contentType: param.contentType || null
155
- })
161
+ contentType: param.contentType || null,
162
+ });
156
163
  }
157
- })
164
+ });
158
165
 
159
166
  if (isNativeFormData) {
160
- for (var data of formDataIterator(form, boundary)) {
161
- request.postData.text += data
167
+ // eslint-disable-next-line no-restricted-syntax
168
+ for (const data of formDataIterator(form, boundary)) {
169
+ request.postData.text += data;
162
170
  }
163
171
  } else {
164
- form.pipe(es.map(function (data, cb) {
165
- request.postData.text += data
166
- }))
172
+ form.pipe(
173
+ // eslint-disable-next-line array-callback-return
174
+ es.map(function (data) {
175
+ request.postData.text += data;
176
+ })
177
+ );
167
178
  }
168
179
 
169
- request.postData.boundary = boundary
180
+ request.postData.boundary = boundary;
170
181
 
171
182
  // Since headers are case-sensitive we need to see if there's an existing `Content-Type` header that we can
172
183
  // override.
173
184
  const contentTypeHeader = helpers.hasHeader(request.headersObj, 'content-type')
174
185
  ? helpers.getHeaderName(request.headersObj, 'content-type')
175
- : 'content-type'
186
+ : 'content-type';
176
187
 
177
- request.headersObj[contentTypeHeader] = 'multipart/form-data; boundary=' + boundary
188
+ request.headersObj[contentTypeHeader] = `multipart/form-data; boundary=${boundary}`;
178
189
  }
179
- break
190
+ break;
180
191
 
181
192
  case 'application/x-www-form-urlencoded':
182
193
  if (!request.postData.params) {
183
- request.postData.text = ''
194
+ request.postData.text = '';
184
195
  } else {
185
- request.postData.paramsObj = request.postData.params.reduce(reducer, {})
196
+ request.postData.paramsObj = request.postData.params.reduce(reducer, {});
186
197
 
187
198
  // always overwrite
188
- request.postData.text = qs.stringify(request.postData.paramsObj)
199
+ request.postData.text = qs.stringify(request.postData.paramsObj);
189
200
  }
190
- break
201
+ break;
191
202
 
192
203
  case 'text/json':
193
204
  case 'text/x-json':
194
205
  case 'application/json':
195
206
  case 'application/x-json':
196
- request.postData.mimeType = 'application/json'
207
+ request.postData.mimeType = 'application/json';
197
208
 
198
209
  if (request.postData.text) {
199
210
  try {
200
- request.postData.jsonObj = JSON.parse(request.postData.text)
211
+ request.postData.jsonObj = JSON.parse(request.postData.text);
201
212
  } catch (e) {
202
213
  // force back to text/plain
203
214
  // if headers have proper content-type value, then this should also work
204
- request.postData.mimeType = 'text/plain'
215
+ request.postData.mimeType = 'text/plain';
205
216
  }
206
217
  }
207
- break
218
+ break;
219
+
220
+ default:
221
+ // no-op
208
222
  }
209
223
 
210
224
  // create allHeaders object
211
- request.allHeaders = Object.assign(request.allHeaders, request.headersObj)
225
+ request.allHeaders = Object.assign(request.allHeaders, request.headersObj);
212
226
 
213
227
  // deconstruct the uri
214
- request.uriObj = url.parse(request.url, true, true)
228
+ // eslint-disable-next-line node/no-deprecated-api
229
+ request.uriObj = url.parse(request.url, true, true);
215
230
 
216
231
  // merge all possible queryString values
217
- request.queryObj = Object.assign(request.queryObj, request.uriObj.query)
232
+ request.queryObj = Object.assign(request.queryObj, request.uriObj.query);
218
233
 
219
234
  // reset uriObj values for a clean url
220
- request.uriObj.query = null
221
- request.uriObj.search = null
222
- request.uriObj.path = request.uriObj.pathname
235
+ request.uriObj.query = null;
236
+ request.uriObj.search = null;
237
+ request.uriObj.path = request.uriObj.pathname;
223
238
 
224
239
  // keep the base url clean of queryString
225
- request.url = url.format(request.uriObj)
240
+ request.url = url.format(request.uriObj);
226
241
 
227
242
  // update the uri object
228
- request.uriObj.query = request.queryObj
229
- if (options.escapeQueryStrings) {
243
+ request.uriObj.query = request.queryObj;
244
+ if (options.harIsAlreadyEncoded) {
230
245
  request.uriObj.search = qs.stringify(request.queryObj, {
231
- indices: false
232
- })
246
+ encode: false,
247
+ indices: false,
248
+ });
233
249
  } else {
234
250
  request.uriObj.search = qs.stringify(request.queryObj, {
235
- encode: false,
236
- indices: false
237
- })
251
+ indices: false,
252
+ });
238
253
  }
239
254
 
240
255
  if (request.uriObj.search) {
241
- request.uriObj.path = request.uriObj.pathname + '?' + request.uriObj.search
256
+ request.uriObj.path = `${request.uriObj.pathname}?${request.uriObj.search}`;
242
257
  }
243
258
 
244
259
  // construct a full url
245
- request.fullUrl = url.format(request.uriObj)
260
+ request.fullUrl = url.format(request.uriObj);
246
261
 
247
- return request
248
- }
262
+ return request;
263
+ };
249
264
 
250
265
  HTTPSnippet.prototype.convert = function (target, client, opts) {
251
266
  if (!opts && client) {
252
- opts = client
267
+ // eslint-disable-next-line no-param-reassign
268
+ opts = client;
253
269
  }
254
270
 
255
- var func = this._matchTarget(target, client)
256
-
271
+ const func = this._matchTarget(target, client);
257
272
  if (func) {
258
- var results = this.requests.map(function (request) {
259
- return func(request, opts)
260
- })
273
+ const results = this.requests.map(function (request) {
274
+ return func(request, opts);
275
+ });
261
276
 
262
- return results.length === 1 ? results[0] : results
277
+ return results.length === 1 ? results[0] : results;
263
278
  }
264
279
 
265
- return false
266
- }
280
+ return false;
281
+ };
267
282
 
268
283
  HTTPSnippet.prototype._matchTarget = function (target, client) {
269
284
  // does it exist?
285
+ // eslint-disable-next-line no-prototype-builtins
270
286
  if (!targets.hasOwnProperty(target)) {
271
- return false
287
+ return false;
272
288
  }
273
289
 
274
290
  // shorthand
275
291
  if (typeof client === 'string' && typeof targets[target][client] === 'function') {
276
- return targets[target][client]
292
+ return targets[target][client];
277
293
  }
278
294
 
279
295
  // default target
280
- return targets[target][targets[target].info.default]
281
- }
296
+ return targets[target][targets[target].info.default];
297
+ };
282
298
 
283
299
  // exports
284
- module.exports = HTTPSnippet
300
+ module.exports = HTTPSnippet;
285
301
 
286
302
  module.exports.addTarget = function (target) {
287
303
  if (!('info' in target)) {
288
- throw new Error('The supplied custom target must contain an `info` object.')
289
- } else if (!('key' in target.info) || !('title' in target.info) || !('extname' in target.info) || !('default' in target.info)) {
290
- throw new Error('The supplied custom target must have an `info` object with a `key`, `title`, `extname`, and `default` property.')
304
+ throw new Error('The supplied custom target must contain an `info` object.');
305
+ } else if (
306
+ !('key' in target.info) ||
307
+ !('title' in target.info) ||
308
+ !('extname' in target.info) ||
309
+ !('default' in target.info)
310
+ ) {
311
+ throw new Error(
312
+ 'The supplied custom target must have an `info` object with a `key`, `title`, `extname`, and `default` property.'
313
+ );
314
+ // eslint-disable-next-line no-prototype-builtins
291
315
  } else if (targets.hasOwnProperty(target.info.key)) {
292
- throw new Error('The supplied custom target already exists.')
316
+ throw new Error('The supplied custom target already exists.');
293
317
  } else if (Object.keys(target).length === 1) {
294
- throw new Error('A custom target must have a client defined on it.')
318
+ throw new Error('A custom target must have a client defined on it.');
295
319
  }
296
320
 
297
- targets[target.info.key] = target
298
- }
321
+ targets[target.info.key] = target;
322
+ };
299
323
 
300
324
  module.exports.addTargetClient = function (target, client) {
325
+ // eslint-disable-next-line no-prototype-builtins
301
326
  if (!targets.hasOwnProperty(target)) {
302
- throw new Error(`Sorry, but no ${target} target exists to add clients to.`)
327
+ throw new Error(`Sorry, but no ${target} target exists to add clients to.`);
303
328
  } else if (!('info' in client)) {
304
- throw new Error('The supplied custom target client must contain an `info` object.')
329
+ throw new Error('The supplied custom target client must contain an `info` object.');
305
330
  } else if (!('key' in client.info) || !('title' in client.info)) {
306
- throw new Error('The supplied custom target client must have an `info` object with a `key` and `title` property.')
331
+ throw new Error('The supplied custom target client must have an `info` object with a `key` and `title` property.');
332
+ // eslint-disable-next-line no-prototype-builtins
307
333
  } else if (targets[target].hasOwnProperty(client.info.key)) {
308
- throw new Error('The supplied custom target client already exists, please use a different key')
334
+ throw new Error('The supplied custom target client already exists, please use a different key');
309
335
  }
310
336
 
311
- targets[target][client.info.key] = client
312
- }
337
+ targets[target][client.info.key] = client;
338
+ };
313
339
 
314
340
  module.exports.availableTargets = function () {
315
341
  return Object.keys(targets).map(function (key) {
316
- var target = Object.assign({}, targets[key].info)
317
- var clients = Object.keys(targets[key])
318
-
342
+ const target = { ...targets[key].info };
343
+ const clients = Object.keys(targets[key])
319
344
  .filter(function (prop) {
320
- return !~['info', 'index'].indexOf(prop)
345
+ return !['info', 'index'].includes(prop);
321
346
  })
322
-
323
347
  .map(function (client) {
324
- return targets[key][client].info
325
- })
348
+ return targets[key][client].info;
349
+ });
326
350
 
327
351
  if (clients.length) {
328
- target.clients = clients
352
+ target.clients = clients;
329
353
  }
330
354
 
331
- return target
332
- })
333
- }
355
+ return target;
356
+ });
357
+ };
334
358
 
335
359
  module.exports.extname = function (target) {
336
- return targets[target] ? targets[target].info.extname : ''
337
- }
360
+ return targets[target] ? targets[target].info.extname : '';
361
+ };
@@ -1,12 +1,10 @@
1
- 'use strict'
2
-
3
1
  module.exports = {
4
2
  info: {
5
3
  key: 'c',
6
4
  title: 'C',
7
5
  extname: '.c',
8
- default: 'libcurl'
6
+ default: 'libcurl',
9
7
  },
10
8
 
11
- libcurl: require('./libcurl')
12
- }
9
+ libcurl: require('./libcurl'),
10
+ };
@@ -1,50 +1,45 @@
1
- 'use strict'
1
+ const CodeBuilder = require('../../helpers/code-builder');
2
2
 
3
- var CodeBuilder = require('../../helpers/code-builder')
3
+ module.exports = function (source) {
4
+ const code = new CodeBuilder();
4
5
 
5
- module.exports = function (source, options) {
6
- var code = new CodeBuilder()
7
-
8
- code.push('CURL *hnd = curl_easy_init();')
9
- .blank()
10
- .push('curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "%s");', source.method.toUpperCase())
11
- .push('curl_easy_setopt(hnd, CURLOPT_URL, "%s");', source.fullUrl)
6
+ code
7
+ .push('CURL *hnd = curl_easy_init();')
8
+ .blank()
9
+ .push('curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "%s");', source.method.toUpperCase())
10
+ .push('curl_easy_setopt(hnd, CURLOPT_URL, "%s");', source.fullUrl);
12
11
 
13
12
  // Add headers, including the cookies
14
- var headers = Object.keys(source.headersObj)
13
+ const headers = Object.keys(source.headersObj);
15
14
 
16
15
  // construct headers
17
16
  if (headers.length) {
18
- code.blank()
19
- .push('struct curl_slist *headers = NULL;')
17
+ code.blank().push('struct curl_slist *headers = NULL;');
20
18
 
21
19
  headers.forEach(function (key) {
22
- code.push('headers = curl_slist_append(headers, "%s: %s");', key, source.headersObj[key])
23
- })
20
+ code.push('headers = curl_slist_append(headers, "%s: %s");', key, source.headersObj[key]);
21
+ });
24
22
 
25
- code.push('curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);')
23
+ code.push('curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);');
26
24
  }
27
25
 
28
26
  // construct cookies
29
27
  if (source.allHeaders.cookie) {
30
- code.blank()
31
- .push('curl_easy_setopt(hnd, CURLOPT_COOKIE, "%s");', source.allHeaders.cookie)
28
+ code.blank().push('curl_easy_setopt(hnd, CURLOPT_COOKIE, "%s");', source.allHeaders.cookie);
32
29
  }
33
30
 
34
31
  if (source.postData.text) {
35
- code.blank()
36
- .push('curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, %s);', JSON.stringify(source.postData.text))
32
+ code.blank().push('curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, %s);', JSON.stringify(source.postData.text));
37
33
  }
38
34
 
39
- code.blank()
40
- .push('CURLcode ret = curl_easy_perform(hnd);')
35
+ code.blank().push('CURLcode ret = curl_easy_perform(hnd);');
41
36
 
42
- return code.join()
43
- }
37
+ return code.join();
38
+ };
44
39
 
45
40
  module.exports.info = {
46
41
  key: 'libcurl',
47
42
  title: 'Libcurl',
48
43
  link: 'http://curl.haxx.se/libcurl/',
49
- description: 'Simple REST and HTTP API Client for C'
50
- }
44
+ description: 'Simple REST and HTTP API Client for C',
45
+ };