Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Serialize data into the URL once. Avoid modifying config.data and con…

…fig.method within send()
  • Loading branch information...
commit 1473f43350715627fdb6a6ea7ec57ad3db6c2048 1 parent 2ddeeb2
@chrisklaiber chrisklaiber authored
Showing with 17 additions and 23 deletions.
  1. +17 −23 lib/yui3-io.js
View
40 lib/yui3-io.js
@@ -11,11 +11,6 @@ YUI.add('io-nodejs', function(Y) {
https = YUI.require('https');
}
- var _concat = function(uri, data) {
- uri += (uri.indexOf('?') === -1 ? '?' : '&') + data;
- return uri;
- };
-
var NodeTransport = {
id: 'nodejs',
src: {
@@ -26,12 +21,10 @@ YUI.add('io-nodejs', function(Y) {
Y.io.xdrResponse('start', transactionObject, config);
var urlInfo = url.parse(uri, parseQueryString=false),
- p = YUI.urlInfoPort(urlInfo);
+ p = YUI.urlInfoPort(urlInfo),
+ method = config.method ? config.method.toUpperCase() : 'GET',
+ data = config.data;
- if (!config.method) {
- config.method = 'GET';
- }
- config.method = config.method.toUpperCase();
if (!config.headers) {
config.headers = {};
}
@@ -44,25 +37,26 @@ YUI.add('io-nodejs', function(Y) {
if (urlInfo.search) {
req_url += urlInfo.search;
}
- if (config.data) {
- if (Y.Lang.isObject(config.data) && Y.QueryString) {
+ if (data) {
+ if (Y.Lang.isObject(data) && Y.QueryString) {
Y.log('Converting config.data Object to String', 'info', 'io');
- config.data = Y.QueryString.stringify(config.data);
+ data = Y.QueryString.stringify(data);
}
- switch (config.method) {
+ switch (method) {
case 'GET':
case 'HEAD':
case 'DELETE':
- req_url = _concat(req_url, config.data);
- config.data = '';
- Y.log('HTTP' + config.method + ' with data. The querystring is: ' + uri, 'info', 'io');
+ // The data object was serialized into the query
+ // string by send() in io-base.
+ data = '';
+ Y.log('HTTP' + method + ' with data. The querystring is: ' + uri, 'info', 'io');
break;
case 'POST':
case 'PUT':
// If Content-Type is defined in the configuration object, or
// or as a default header, it will be used instead of
// 'application/x-www-form-urlencoded; charset=UTF-8'
- config.headers['Content-Length'] = config.data.length;
+ config.headers['Content-Length'] = data.length;
config.headers = Y.merge({
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}, config.headers);
@@ -70,7 +64,7 @@ YUI.add('io-nodejs', function(Y) {
}
}
- Y.log('Requesting (' + config.method + '): ' + urlInfo.hostname, 'info', 'nodeio');
+ Y.log('Requesting (' + method + '): ' + urlInfo.hostname, 'info', 'nodeio');
if (http.get) { //0.4.0
Y.log('Using new 0.4.0 http.request', 'info', 'nodeio');
var h = ((urlInfo.protocol === 'https') || p === 443) ? https : http;
@@ -81,14 +75,14 @@ YUI.add('io-nodejs', function(Y) {
var request = h.request({
host: urlInfo.hostname,
port: p,
- method: config.method,
+ method: method,
path: req_url,
headers: config.headers
});
var s = request;
} else {
var host = http.createClient(p, urlInfo.hostname, ((p === 443) ? true : false));
- var request = host.request(config.method, req_url, config.headers);
+ var request = host.request(method, req_url, config.headers);
var s = request.socket || request;
}
Y.log('URL: ' + req_url, 'info', 'nodeio');
@@ -163,8 +157,8 @@ YUI.add('io-nodejs', function(Y) {
});
});
- if (config.method !== 'GET') {
- request.write(config.data);
+ if (data) {
+ request.write(data);
}
if (request.end) {
request.end();
Please sign in to comment.
Something went wrong with that request. Please try again.