Permalink
Browse files

made the appropriate fix this time

  • Loading branch information...
1 parent c9d4903 commit f2a01e519b016ab796f6b547bd2003223896aebe @coolaj86 committed Feb 10, 2012
Showing with 42 additions and 11 deletions.
  1. +4 −3 lib/lib/connect-pathname.js
  2. +3 −3 lib/package.json
  3. +35 −5 test.js
@@ -2,15 +2,16 @@
"use strict";
var url = require('url')
+ , querystring = require('querystring')
;
function pathnameParser(req, res, next) {
var urlObj
;
- urlObj = req.query || url.parse(req.url, true);
- req.query = urlObj.query || {};
- req.pathname = req.pathname || urlObj.pathname || '/';
+ urlObj = url.parse(req.url);
+ req.pathname = req.pathname || urlObj.pathname;
+ req.query = req.query || querystring.parse(urlObj.search);
next();
}
View
@@ -2,7 +2,7 @@
"author": "AJ ONeal <coolaj86@gmail.com> (http://coolaj86.info)",
"name": "steve",
"description": "JSON's best friend (a CORS/XHR2 application platform)",
- "version": "0.5.4",
+ "version": "0.5.6",
"repository": {
"type": "git",
"url": "git://github.com/coolaj86/steve.git"
@@ -12,8 +12,8 @@
"node": ">= 0.4.0"
},
"dependencies": {
- "connect": ">= 1.0.0"
- , "nowww": ">= 1.1.0"
+ "connect": "1.8.x"
+ , "nowww": ">= 1.1.x"
, "connect-xcors": ">= 0.0.0"
, "express-chromeframe": ">= 0.2.0"
},
View
40 test.js
@@ -3,21 +3,51 @@
var connect = require('./lib/index')
, request = require('ahr2')
+ , assert = require('assert')
, server
+ , protocol = 'http:'
+ , hostname = 'localhost'
+ , port = '6767'
+ , pathname = '/path/to/resource'
+ , search = 'search=query&foo=bar'
+ , url = pathname + '?' + search
+ , fullurl = protocol + '//' + hostname + ':' + port + pathname + '?' + search
+ , query = {
+ search: 'query'
+ , foo: 'bar'
+ }
;
- server = connect.createServer();
+ server = connect.createServer(function (req, res, next) {
+ console.log(req.url);
+ res.json({
+ "url": req.url
+ //, "adddress": req.socket.address()
+ //, "protocol": req.protocol
+ , "pathname": req.pathname
+ , "query": req.query
+ //, "search": req.search
+ , "path": req.path
+ });
+ });
- server.listen(6767, function () {
- request.get('http://localhost:6767/').when(function (err, ahr, data) {
+ server.listen(port, function () {
+ request.get(fullurl).when(function (err, ahr, data) {
server.close();
if (err) {
console.error(err);
return;
}
- console.info('data:');
- console.log(data.toString('utf8'));
+ data = data.result;
+ assert.strictEqual(url, data.url, "urls don't match");
+ //assert.strictEqual(protocol, data.protocol, "protocol don't match");
+ //assert.strictEqual(hostname, data.hostname, "hostnames don't match");
+ //assert.strictqual(port, data.port, "ports don't match");
+ assert.strictEqual(pathname, data.pathname, "pathnames don't match");
+ //assert.strictEqual(search, data.search, "searchs don't match");
+ assert.deepEqual(query, data.query, "queries don't match");
+ console.log('tests pass (ctrl+c to exit)');
});
});

0 comments on commit f2a01e5

Please sign in to comment.