mirror of
https://github.com/curlconverter/curlconverter.git
synced 2022-05-22 02:35:29 +03:00
fix header handling for requests with a single header
This commit is contained in:
1
test/curl8.txt
Normal file
1
test/curl8.txt
Normal file
@@ -0,0 +1 @@
|
||||
curl http://example.com/ -H 'foo: bar'
|
||||
18
test/node_output8.js
Normal file
18
test/node_output8.js
Normal file
@@ -0,0 +1,18 @@
|
||||
var request = require('request');
|
||||
|
||||
var headers = {
|
||||
'foo': 'bar'
|
||||
};
|
||||
|
||||
var options = {
|
||||
url: 'http://example.com/',
|
||||
headers: headers
|
||||
};
|
||||
|
||||
function callback(error, response, body) {
|
||||
if (!error && response.statusCode == 200) {
|
||||
console.log(body);
|
||||
}
|
||||
}
|
||||
|
||||
request(options, callback);
|
||||
10
test/test.js
10
test/test.js
@@ -162,4 +162,12 @@ test('http post with data - php', function (t) {
|
||||
var goodPhpCode = fs.readFileSync(__dirname + '/php_output3.php', 'utf-8').trim();
|
||||
t.equal(phpCode, goodPhpCode);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('http get with single header - node', function (t) {
|
||||
var curlHttpPostCommand = fs.readFileSync(__dirname + '/curl8.txt', 'utf-8');
|
||||
var nodeCode = curlconverter.toNode(curlHttpPostCommand);
|
||||
var goodNodeCode = fs.readFileSync(__dirname + '/node_output8.js', 'utf-8').trim();
|
||||
t.equal(nodeCode, goodNodeCode);
|
||||
t.end();
|
||||
});
|
||||
|
||||
3
util.js
3
util.js
@@ -22,6 +22,9 @@ var parseCurlCommand = function(curlCommand) {
|
||||
var headers;
|
||||
if (parsedArguments.H) {
|
||||
headers = {};
|
||||
if (!Array.isArray(parsedArguments.H)) {
|
||||
parsedArguments.H = [parsedArguments.H];
|
||||
}
|
||||
parsedArguments.H.forEach(function (header) {
|
||||
if (header.indexOf('Cookie') !== -1) {
|
||||
cookieString = header;
|
||||
|
||||
Reference in New Issue
Block a user