Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed logic behind headers and data writing

  • Loading branch information...
commit e8c0c91e682dcc83be1bd526ab64cacca4d035d9 1 parent 4f9354c
@davglass authored
Showing with 48 additions and 7 deletions.
  1. +29 −7 lib/yui3-io.js
  2. +19 −0 tests/interface.js
View
36 lib/yui3-io.js
@@ -11,6 +11,11 @@ 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: {
@@ -35,19 +40,36 @@ YUI.add('io-nodejs', function(Y) {
config.headers.host = config.headers.host || _headers.host;
+ var req_url = urlInfo.pathname;
+ if (urlInfo.search) {
+ req_url += urlInfo.search;
+ }
if (config.data) {
if (Y.Lang.isObject(config.data) && Y.QueryString) {
Y.log('Converting config.data Object to String', 'info', 'io');
config.data = Y.QueryString.stringify(config.data);
}
- config.headers['Content-Length'] = config.data.length;
- config.headers = Y.merge({ 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }, config.headers);
- }
-
- var req_url = urlInfo.pathname;
- if (urlInfo.search) {
- req_url += urlInfo.search;
+ switch (config.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');
+ 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 = Y.merge({
+ 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
+ }, config.headers);
+ break;
+ }
}
+
Y.log('Requesting (' + config.method + '): ' + urlInfo.hostname, 'info', 'nodeio');
if (http.get) { //0.4.0
Y.log('Using new 0.4.0 http.request', 'info', 'nodeio');
View
19 tests/interface.js
@@ -123,6 +123,25 @@ suite.add( new YUITest.TestCase({
});
});
}),
+ "io get test with data" : async(function (data, next) {
+ yui3.silent().use("loader", 'io', function (Y) {
+ Y.io('http://login.yahoo.com/', {
+ method: 'GET',
+ data: {
+ foo: 'nodejs',
+ bar: 'davglass'
+ },
+ on: {
+ complete: function(id, e) {
+ Assert.isObject(Y.Loader);
+ Assert.isFunction(Y.io);
+ //It made it here, no socket hang up
+ next();
+ }
+ }
+ });
+ });
+ }),
"io post test" : async(function (data, next) {
yui3.silent().use("loader", 'io', function (Y) {
Y.io('http://login.yahoo.com/', {
Please sign in to comment.
Something went wrong with that request. Please try again.