mirror of
https://github.com/curlconverter/curlconverter.git
synced 2022-05-22 02:35:29 +03:00
added node.js support
This commit is contained in:
24
test/node_output1.js
Normal file
24
test/node_output1.js
Normal file
@@ -0,0 +1,24 @@
|
||||
var request = require('request');
|
||||
|
||||
var headers = {
|
||||
'Accept-Encoding': 'gzip, deflate, sdch',
|
||||
'Accept-Language': 'en-US,en;q=0.8',
|
||||
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36',
|
||||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
|
||||
'Referer': 'http://www.wikipedia.org/',
|
||||
'Connection': 'keep-alive',
|
||||
'Cookie': 'GeoIP=US:Albuquerque:35.1241:-106.7675:v4; uls-previous-languages=%5B%22en%22%5D; mediaWiki.user.sessionId=VaHaeVW3m0ymvx9kacwshZIDkv8zgF9y; centralnotice_buckets_by_campaign=%7B%22C14_enUS_dsk_lw_FR%22%3A%7B%22val%22%3A%220%22%2C%22start%22%3A1412172000%2C%22end%22%3A1422576000%7D%2C%22C14_en5C_dec_dsk_FR%22%3A%7B%22val%22%3A3%2C%22start%22%3A1417514400%2C%22end%22%3A1425290400%7D%2C%22C14_en5C_bkup_dsk_FR%22%3A%7B%22val%22%3A1%2C%22start%22%3A1417428000%2C%22end%22%3A1425290400%7D%7D; centralnotice_bannercount_fr12=22; centralnotice_bannercount_fr12-wait=14'
|
||||
};
|
||||
|
||||
var options = {
|
||||
url: 'http://en.wikipedia.org/',
|
||||
headers: headers
|
||||
};
|
||||
|
||||
function callback(error, response, body) {
|
||||
if (!error && response.statusCode == 200) {
|
||||
console.log(body);
|
||||
}
|
||||
}
|
||||
|
||||
request(options, callback);
|
||||
27
test/node_output2.js
Normal file
27
test/node_output2.js
Normal file
@@ -0,0 +1,27 @@
|
||||
var request = require('request');
|
||||
|
||||
var headers = {
|
||||
'Origin': 'http://www.w3schools.com',
|
||||
'Accept-Encoding': 'gzip, deflate',
|
||||
'Accept-Language': 'en-US,en;q=0.8',
|
||||
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36',
|
||||
'Accept': '*/*',
|
||||
'Referer': 'http://www.w3schools.com/ajax/tryit_view.asp?x=0.07944501144811511',
|
||||
'Connection': 'keep-alive',
|
||||
'Content-Length': '0',
|
||||
'Cookie': '_gat=1; ASPSESSIONIDACCRDTDC=MCMDKFMBLLLHGKCGNMKNGPKI; _ga=GA1.2.1424920226.1419478126'
|
||||
};
|
||||
|
||||
var options = {
|
||||
url: 'http://www.w3schools.com/ajax/demo_post.asp',
|
||||
method: 'POST',
|
||||
headers: headers
|
||||
};
|
||||
|
||||
function callback(error, response, body) {
|
||||
if (!error && response.statusCode == 200) {
|
||||
console.log(body);
|
||||
}
|
||||
}
|
||||
|
||||
request(options, callback);
|
||||
30
test/node_output3.js
Normal file
30
test/node_output3.js
Normal file
@@ -0,0 +1,30 @@
|
||||
var request = require('request');
|
||||
|
||||
var headers = {
|
||||
'Origin': 'http://fiddle.jshell.net',
|
||||
'Accept-Encoding': 'gzip, deflate',
|
||||
'Accept-Language': 'en-US,en;q=0.8',
|
||||
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36',
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||
'Accept': '*/*',
|
||||
'Referer': 'http://fiddle.jshell.net/_display/',
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
'Connection': 'keep-alive'
|
||||
};
|
||||
|
||||
var dataString = 'msg1=wow&msg2=such';
|
||||
|
||||
var options = {
|
||||
url: 'http://fiddle.jshell.net/echo/html/',
|
||||
method: 'POST',
|
||||
headers: headers,
|
||||
data: dataString
|
||||
};
|
||||
|
||||
function callback(error, response, body) {
|
||||
if (!error && response.statusCode == 200) {
|
||||
console.log(body);
|
||||
}
|
||||
}
|
||||
|
||||
request(options, callback);
|
||||
33
test/test.js
33
test/test.js
@@ -8,7 +8,7 @@ test('http get - python', function (t) {
|
||||
var curlHttpGetCommand = fs.readFileSync(__dirname + '/curl1.txt', 'utf-8');
|
||||
var pythonCode = curlconverter.toPython(curlHttpGetCommand);
|
||||
var goodPythonCode = fs.readFileSync(__dirname + '/python_output1.py', 'utf-8');
|
||||
t.equal(goodPythonCode, pythonCode);
|
||||
t.equal(pythonCode, goodPythonCode);
|
||||
t.end();
|
||||
});
|
||||
|
||||
@@ -17,7 +17,7 @@ test('http post - python', function (t) {
|
||||
var curlHttpGetCommand = fs.readFileSync(__dirname + '/curl2.txt', 'utf-8');
|
||||
var pythonCode = curlconverter.toPython(curlHttpGetCommand);
|
||||
var goodPythonCode = fs.readFileSync(__dirname + '/python_output2.py', 'utf-8');
|
||||
t.equal(goodPythonCode, pythonCode);
|
||||
t.equal(pythonCode, goodPythonCode);
|
||||
t.end();
|
||||
});
|
||||
|
||||
@@ -25,8 +25,33 @@ test('http post - python', function (t) {
|
||||
test('http post with data - python', function (t) {
|
||||
var curlHttpGetCommand = fs.readFileSync(__dirname + '/curl3.txt', 'utf-8');
|
||||
var pythonCode = curlconverter.toPython(curlHttpGetCommand);
|
||||
console.log(pythonCode);
|
||||
var goodPythonCode = fs.readFileSync(__dirname + '/python_output3.py', 'utf-8');
|
||||
t.equal(goodPythonCode, pythonCode);
|
||||
t.equal(pythonCode, goodPythonCode);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('http get - node', function (t) {
|
||||
var curlHttpGetCommand = fs.readFileSync(__dirname + '/curl1.txt', 'utf-8');
|
||||
var nodeCode = curlconverter.toNode(curlHttpGetCommand);
|
||||
var goodNodeCode = fs.readFileSync(__dirname + '/node_output1.js', 'utf-8');
|
||||
t.equal(nodeCode, goodNodeCode);
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
||||
test('http post - node', function (t) {
|
||||
var curlHttpGetCommand = fs.readFileSync(__dirname + '/curl2.txt', 'utf-8');
|
||||
var nodeCode = curlconverter.toNode(curlHttpGetCommand);
|
||||
var goodNodeCode = fs.readFileSync(__dirname + '/node_output2.js', 'utf-8');
|
||||
t.equal(nodeCode, goodNodeCode);
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
||||
test('http post with data - node', function (t) {
|
||||
var curlHttpGetCommand = fs.readFileSync(__dirname + '/curl3.txt', 'utf-8');
|
||||
var nodeCode = curlconverter.toNode(curlHttpGetCommand);
|
||||
var goodNodeCode = fs.readFileSync(__dirname + '/node_output3.js', 'utf-8');
|
||||
t.equal(nodeCode, goodNodeCode);
|
||||
t.end();
|
||||
});
|
||||
Reference in New Issue
Block a user