Skip to content

Commit f601ecc

Browse files
committed
[Kong#11][feature] added headers, cookies, json and form samples in test
1 parent 39c55e1 commit f601ecc

4 files changed

Lines changed: 31 additions & 65 deletions

File tree

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,17 @@
1-
var http = require("http");
1+
var request = require('request');
22
var querystring = require("querystring");
33

44
var options = {
5-
"method": "POST",
6-
"hostname": "mockbin.com",
7-
"port": null,
8-
"path": "/har?",
9-
"headers": {
5+
url: 'http://mockbin.com/har?',
6+
body: querystring.stringify({"foo": "bar"}),
7+
headers: {
108
"Content-Type": "application/x-www-form-urlencoded"
119
}
12-
};
13-
14-
var req = http.request(options, function (res) {
15-
var chunks = [];
16-
17-
res.on("data", function (chunk) {
18-
chunks.push(chunk);
19-
});
20-
21-
res.on("end", function () {
22-
var body = Buffer.concat(chunks);
23-
});
10+
}
11+
request.post(options, function(error, response, body) {
12+
if (error){
13+
//throw error here
14+
return;
15+
}
16+
// work with response and body here;
2417
});
25-
26-
var postData = querystring.stringify({"foo":"bar"});
27-
req.write(postData);
28-
req.end();
Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,14 @@
1-
var http = require("http");
1+
var request = require('request');
22

33
var options = {
4-
"method": "POST",
5-
"hostname": "mockbin.com",
6-
"port": null,
7-
"path": "/har?",
8-
"headers": {
9-
"Content-Type": "application/json"
4+
url: 'http://mockbin.com/har?',
5+
body: JSON.stringify({"foo": "bar"}),
6+
json:true
7+
}
8+
request.post(options, function(error, response, body) {
9+
if (error){
10+
//throw error here
11+
return;
1012
}
11-
};
12-
13-
var req = http.request(options, function (res) {
14-
var chunks = [];
15-
16-
res.on("data", function (chunk) {
17-
chunks.push(chunk);
18-
});
19-
20-
res.on("end", function () {
21-
var body = Buffer.concat(chunks);
22-
});
13+
// work with response and body here;
2314
});
24-
25-
req.write("{\"foo\": \"bar\"}");
26-
req.end();
Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
1-
var http = require("http");
1+
var request = require('request');
22

33
var options = {
4-
"method": "POST",
5-
"hostname": "mockbin.com",
6-
"port": null,
7-
"path": "/har?",
8-
"headers": {
4+
url: 'http://mockbin.com/har?',
5+
headers: {
96
"Cookie": "foo=bar; bar=baz"
107
}
11-
};
12-
13-
var req = http.request(options, function (res) {
14-
var chunks = [];
15-
16-
res.on("data", function (chunk) {
17-
chunks.push(chunk);
18-
});
19-
20-
res.on("end", function () {
21-
var body = Buffer.concat(chunks);
22-
});
8+
}
9+
request.post(options, function(error, response, body) {
10+
if (error){
11+
//throw error here
12+
return;
13+
}
14+
// work with response and body here;
2315
});
24-
25-
req.end();

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@ request.get(options, function(error, response, body) {
1212
//throw error here
1313
return;
1414
}
15-
console.log(body);
1615
// work with response and body here;
1716
});

0 commit comments

Comments
 (0)