Skip to content

Commit 86bed31

Browse files
committed
node 0.10 support
1 parent a95ff12 commit 86bed31

16 files changed

Lines changed: 97 additions & 153 deletions

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ language: node_js
33
node_js:
44
- iojs
55
- 0.12
6+
- 0.11
7+
- 0.10
68

79
script: npm run travis
810

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"xmlhttprequest"
3030
],
3131
"engines": {
32-
"node": ">=0.12"
32+
"node": ">=0.10"
3333
},
3434
"files": [
3535
"bin",

src/targets/node/request.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
'use strict'
1212

1313
var util = require('util')
14-
var path = require('path')
1514
var CodeBuilder = require('../../helpers/code-builder')
1615

1716
module.exports = function (source, options) {
@@ -56,6 +55,11 @@ module.exports = function (source, options) {
5655
source.postData.params.forEach(function (param) {
5756
var attachement = {}
5857

58+
if (!param.fileName && !param.fileName && !param.contentType) {
59+
reqOpts.formData[param.name] = param.value
60+
return
61+
}
62+
5963
if (param.fileName && !param.value) {
6064
includeFS = true
6165

@@ -65,10 +69,8 @@ module.exports = function (source, options) {
6569
}
6670

6771
if (param.fileName) {
68-
var base = path.parse(param.fileName).base
69-
7072
attachement.options = {
71-
filename: base.length ? base : 'filename',
73+
filename: param.fileName,
7274
contentType: param.contentType ? param.contentType : null
7375
}
7476
}
@@ -101,7 +103,12 @@ module.exports = function (source, options) {
101103
code.unshift('var fs = require("fs");')
102104
}
103105

104-
code.push(util.format('request(%s, %s', JSON.stringify(reqOpts, null, opts.indent), 'function (error, response, body) {'))
106+
code.push(util.format('var options = %s;', util.inspect(reqOpts, {
107+
depth: null
108+
})))
109+
.blank()
110+
111+
code.push(util.format('request(options, %s', 'function (error, response, body) {'))
105112
.push(1, 'if (error) throw new Error(error);')
106113
.blank()
107114
.push(1, 'console.log(body);')

test/fixtures/output/node/request/application-form-encoded.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
var request = require("request");
22

3-
request({
4-
"method": "POST",
5-
"url": "http://mockbin.com/har",
6-
"headers": {
7-
"content-type": "application/x-www-form-urlencoded"
8-
},
9-
"form": {
10-
"foo": "bar",
11-
"hello": "world"
12-
}
13-
}, function (error, response, body) {
3+
var options = { method: 'POST',
4+
url: 'http://mockbin.com/har',
5+
headers: { 'content-type': 'application/x-www-form-urlencoded' },
6+
form: { foo: 'bar', hello: 'world' } };
7+
8+
request(options, function (error, response, body) {
149
if (error) throw new Error(error);
1510

1611
console.log(body);

test/fixtures/output/node/request/application-json.js

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,17 @@
11
var request = require("request");
22

3-
request({
4-
"method": "POST",
5-
"url": "http://mockbin.com/har",
6-
"headers": {
7-
"content-type": "application/json"
8-
},
9-
"body": {
10-
"number": 1,
11-
"string": "f\"oo",
12-
"arr": [
13-
1,
14-
2,
15-
3
16-
],
17-
"nested": {
18-
"a": "b"
19-
},
20-
"arr_mix": [
21-
1,
22-
"a",
23-
{
24-
"arr_mix_nested": {}
25-
}
26-
]
27-
},
28-
"json": true
29-
}, function (error, response, body) {
3+
var options = { method: 'POST',
4+
url: 'http://mockbin.com/har',
5+
headers: { 'content-type': 'application/json' },
6+
body:
7+
{ number: 1,
8+
string: 'f"oo',
9+
arr: [ 1, 2, 3 ],
10+
nested: { a: 'b' },
11+
arr_mix: [ 1, 'a', { arr_mix_nested: {} } ] },
12+
json: true };
13+
14+
request(options, function (error, response, body) {
3015
if (error) throw new Error(error);
3116

3217
console.log(body);

test/fixtures/output/node/request/cookies.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ var jar = request.jar();
44
jar.setCookie(request.cookie("foo=bar"), "http://mockbin.com/har");
55
jar.setCookie(request.cookie("bar=baz"), "http://mockbin.com/har");
66

7-
request({
8-
"method": "POST",
9-
"url": "http://mockbin.com/har",
10-
"jar": jar
11-
}, function (error, response, body) {
7+
var options = { method: 'POST', url: 'http://mockbin.com/har', jar: 'JAR' };
8+
9+
request(options, function (error, response, body) {
1210
if (error) throw new Error(error);
1311

1412
console.log(body);

test/fixtures/output/node/request/custom-method.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
var request = require("request");
22

3-
request({
4-
"method": "PROPFIND",
5-
"url": "http://mockbin.com/har"
6-
}, function (error, response, body) {
3+
var options = { method: 'PROPFIND', url: 'http://mockbin.com/har' };
4+
5+
request(options, function (error, response, body) {
76
if (error) throw new Error(error);
87

98
console.log(body);

test/fixtures/output/node/request/full.js

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,16 @@ var jar = request.jar();
44
jar.setCookie(request.cookie("foo=bar"), "http://mockbin.com/har");
55
jar.setCookie(request.cookie("bar=baz"), "http://mockbin.com/har");
66

7-
request({
8-
"method": "POST",
9-
"url": "http://mockbin.com/har",
10-
"qs": {
11-
"foo": [
12-
"bar",
13-
"baz"
14-
],
15-
"baz": "abc",
16-
"key": "value"
17-
},
18-
"headers": {
19-
"content-type": "application/x-www-form-urlencoded",
20-
"accept": "application/json"
21-
},
22-
"form": {
23-
"foo": "bar"
24-
},
25-
"jar": jar
26-
}, function (error, response, body) {
7+
var options = { method: 'POST',
8+
url: 'http://mockbin.com/har',
9+
qs: { foo: [ 'bar', 'baz' ], baz: 'abc', key: 'value' },
10+
headers:
11+
{ 'content-type': 'application/x-www-form-urlencoded',
12+
accept: 'application/json' },
13+
form: { foo: 'bar' },
14+
jar: 'JAR' };
15+
16+
request(options, function (error, response, body) {
2717
if (error) throw new Error(error);
2818

2919
console.log(body);

test/fixtures/output/node/request/headers.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
var request = require("request");
22

3-
request({
4-
"method": "GET",
5-
"url": "http://mockbin.com/har",
6-
"headers": {
7-
"x-foo": "Bar",
8-
"accept": "application/json"
9-
}
10-
}, function (error, response, body) {
3+
var options = { method: 'GET',
4+
url: 'http://mockbin.com/har',
5+
headers: { 'x-foo': 'Bar', accept: 'application/json' } };
6+
7+
request(options, function (error, response, body) {
118
if (error) throw new Error(error);
129

1310
console.log(body);

test/fixtures/output/node/request/https.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
var request = require("request");
22

3-
request({
4-
"method": "GET",
5-
"url": "https://mockbin.com/har"
6-
}, function (error, response, body) {
3+
var options = { method: 'GET', url: 'https://mockbin.com/har' };
4+
5+
request(options, function (error, response, body) {
76
if (error) throw new Error(error);
87

98
console.log(body);

0 commit comments

Comments
 (0)