mirror of
https://github.com/curlconverter/curlconverter.git
synced 2022-05-22 02:35:29 +03:00
This commit is contained in:
1
test/curl14.txt
Normal file
1
test/curl14.txt
Normal file
@@ -0,0 +1 @@
|
||||
curl -L http://www.google.com
|
||||
1
test/curl15.txt
Normal file
1
test/curl15.txt
Normal file
@@ -0,0 +1 @@
|
||||
curl -H "Host: api.ipify.org" -H "Accept: */*" -H "User-Agent: GiftTalk/2.7.2 (iPhone; iOS 9.0.2; Scale/3.00)" -H "Accept-Language: en-CN;q=1, zh-Hans-CN;q=0.9" --compressed http://api.ipify.org/?format=json&
|
||||
13
test/node_output14.js
Normal file
13
test/node_output14.js
Normal file
@@ -0,0 +1,13 @@
|
||||
var request = require('request');
|
||||
|
||||
var options = {
|
||||
url: 'http://www.google.com'
|
||||
};
|
||||
|
||||
function callback(error, response, body) {
|
||||
if (!error && response.statusCode == 200) {
|
||||
console.log(body);
|
||||
}
|
||||
}
|
||||
|
||||
request(options, callback);
|
||||
8
test/python_output8.py
Normal file
8
test/python_output8.py
Normal file
@@ -0,0 +1,8 @@
|
||||
headers = {
|
||||
'Host': 'api.ipify.org',
|
||||
'Accept': '*/*',
|
||||
'User-Agent': 'GiftTalk/2.7.2 (iPhone; iOS 9.0.2; Scale/3.00)',
|
||||
'Accept-Language': 'en-CN;q=1, zh-Hans-CN;q=0.9',
|
||||
}
|
||||
|
||||
requests.get('http://api.ipify.org/?format=json&', headers=headers)
|
||||
18
test/test.js
18
test/test.js
@@ -212,3 +212,21 @@ test('http post with escaped double quotes inside double quotes body - node', fu
|
||||
t.equal(nodeCode, goodNodeCode);
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
||||
test('http get with -L param - node', function (t) {
|
||||
var curlHttpPostCommand = fs.readFileSync(__dirname + '/curl14.txt', 'utf-8');
|
||||
var nodeCode = curlconverter.toNode(curlHttpPostCommand);
|
||||
var goodNodeCode = fs.readFileSync(__dirname + '/node_output14.js', 'utf-8').trim();
|
||||
t.equal(nodeCode, goodNodeCode);
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
||||
test('http with charles syntax - python', function (t) {
|
||||
var curlHttpGetCommand = fs.readFileSync(__dirname + '/curl15.txt', 'utf-8');
|
||||
var pythonCode = curlconverter.toPython(curlHttpGetCommand);
|
||||
var goodPythonCode = fs.readFileSync(__dirname + '/python_output8.py', 'utf-8').trim();
|
||||
t.equal(pythonCode, goodPythonCode);
|
||||
t.end();
|
||||
});
|
||||
|
||||
8
util.js
8
util.js
@@ -7,6 +7,14 @@ var parseCurlCommand = function(curlCommand) {
|
||||
var cookieString;
|
||||
var cookies;
|
||||
var url = parsedArguments._[1];
|
||||
// if url argument wasn't where we expected it, check other places
|
||||
// it shows up
|
||||
if (!url && parsedArguments['L']) {
|
||||
url = parsedArguments['L'];
|
||||
}
|
||||
if (!url && parsedArguments['compressed']) {
|
||||
url = parsedArguments['compressed'];
|
||||
}
|
||||
var headers;
|
||||
if (parsedArguments.H) {
|
||||
headers = {};
|
||||
|
||||
Reference in New Issue
Block a user