Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use the new uri parser.

  • Loading branch information...
commit 581438f0edf7b60271f808d656d5692a9f6122be 1 parent 0b9dda1
isaacs authored
Showing with 11 additions and 72 deletions.
  1. +11 −72 lib/http.js
View
83 lib/http.js
@@ -41,74 +41,6 @@ var STATUS_CODES = exports.STATUS_CODES = {
505 : 'HTTP Version not supported'
};
-/*
- parseUri 1.2.1
- (c) 2007 Steven Levithan <stevenlevithan.com>
- MIT License
-*/
-
-function decode (s) {
- return decodeURIComponent(s.replace(/\+/g, ' '));
-}
-
-exports.parseUri = function (str) {
- var o = exports.parseUri.options,
- m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
- uri = {},
- i = 14;
-
- while (i--) uri[o.key[i]] = m[i] || "";
-
- uri[o.q.name] = {};
- uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
- if ($1) {
- try {
- var key = decode($1);
- var val = decode($2);
- } catch (e) {
- return;
- }
- uri[o.q.name][key] = val;
- }
- });
- uri.toString = function () { return str; };
-
- for (i = o.key.length - 1; i >= 0; i--){
- if (uri[o.key[i]] == "") delete uri[o.key[i]];
- }
-
- return uri;
-};
-
-exports.parseUri.options = {
- strictMode: false,
- key: [
- "source",
- "protocol",
- "authority",
- "userInfo",
- "user",
- "password",
- "host",
- "port",
- "relative",
- "path",
- "directory",
- "file",
- "query",
- "anchor"
- ],
- q: {
- name: "params",
- parser: /(?:^|&)([^&=]*)=?([^&]*)/g
- },
- parser: {
- strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
- loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
- }
-};
-
-
var connection_expression = /Connection/i;
var transfer_encoding_expression = /Transfer-Encoding/i;
var close_expression = /close/i;
@@ -142,6 +74,7 @@ function IncomingMessage (connection) {
sys.inherits(IncomingMessage, process.EventEmitter);
exports.IncomingMessage = IncomingMessage;
+var decode = require("uri").decode;
IncomingMessage.prototype._parseQueryString = function () {
var parts = this.uri.queryString.split('&');
for (var j = 0; j < parts.length; j++) {
@@ -631,13 +564,19 @@ exports.cat = function (url, encoding, headers) {
encoding = encoding || "utf8";
- var uri = exports.parseUri(url);
+ var uri = require("uri").parse(url);
headers = headers || {};
- if (!headers["Host"] && uri.host) {
- headers["Host"] = uri.host;
+
+ var hasHost = false;
+ for (var i in headers) if (i.toLowerCase() === "host") {
+ hasHost = true;
+ break;
+ }
+ if (!hasHost) {
+ headers["Host"] = uri.domain;
}
- var client = exports.createClient(uri.port || 80, uri.host);
+ var client = exports.createClient(uri.port || 80, uri.domain);
var req = client.request(uri.path || "/", headers);
client.addListener("error", function () {
Please sign in to comment.
Something went wrong with that request. Please try again.