Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clone params/options with prototype in order to allow FormData instan… #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 12 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ function request(options, callback) {
throw new Error('No options given')

var options_onResponse = options.onResponse; // Save this for later.

if(typeof options === 'string')
if(typeof options === 'string'){
options = {'uri':options};
else
options = JSON.parse(JSON.stringify(options)); // Use a duplicate for mutating.
}else{
// Use a duplicate for mutating.
var cloned = function(){}
cloned.prototype = options;
options = new cloned();
}


options.onResponse = options_onResponse // And put it back.

Expand Down Expand Up @@ -292,7 +297,9 @@ request.defaults = function(options, requester) {
if(typeof params === 'string')
params = {'uri': params};
else {
params = JSON.parse(JSON.stringify(params));
var cloned = function(){}
cloned.prototype = params;
params = new cloned();
}
for (var i in options) {
if (params[i] === undefined) params[i] = options[i]
Expand Down