Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
Cleanup for #148
Browse files Browse the repository at this point in the history
  • Loading branch information
hueniverse committed Nov 5, 2015
1 parent 5e72fa2 commit 10daa13
Show file tree
Hide file tree
Showing 6 changed files with 319 additions and 345 deletions.
37 changes: 14 additions & 23 deletions lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ hawk.client = {
ts: timestamp,
nonce: options.nonce || hawk.utils.randomString(6),
method: method,
resource: uri.relative,
host: uri.hostname,
resource: uri.resource,
host: uri.host,
port: uri.port,
hash: options.hash,
ext: options.ext,
Expand Down Expand Up @@ -201,8 +201,8 @@ hawk.client = {
ts: exp,
nonce: '',
method: 'GET',
resource: uri.relative, // Maintain trailing '?' and query params
host: uri.hostname,
resource: uri.resource, // Maintain trailing '?' and query params
host: uri.host,
port: uri.port,
ext: options.ext
});
Expand Down Expand Up @@ -583,29 +583,20 @@ hawk.utils = {
return result.join('');
},

uriRegex: /^([^:]+)\:\/\/(?:[^@]*@)?([^\/:]+)(?:\:(\d+))?([^#]*)(?:#.*)?$/, // scheme://credentials@host:port/resource#fragment
parseUri: function (input) {
// From RFC 3986 (except for some groups being non-capturing and two extra groups for 'resource' and 'relative')
var uriRegex = /^(?:([^:\/?#]+):)?(?:\/\/([^\/?#]*))?((([^?#]*)(?:\?([^#]*))?)(?:#(.*))?)/;
var uriKeys = ['source', 'protocol', 'authority', 'resource', 'relative', 'pathname', 'query', 'fragment'];
var authRegex = /^(?:(([^:@]*)(?::([^@]*))?)@)?(\[[^\]]*\]|[^:]*)(?::(\d*))?/;
var authKeys = ['authority', 'userInfo', 'user', 'password', 'hostname', 'port'];
var uri = {}, i;

var parts = uriRegex.exec(input);

for (i = 0; i < parts.length; ++i) {
uri[uriKeys[i]] = parts[i] || '';
}

parts = authRegex.exec(uri['authority']);

for (i = 0; i < parts.length; ++i) {
uri[authKeys[i]] = parts[i] || '';
var parts = input.match(hawk.utils.uriRegex);
if (!parts) {
return { host: '', port: '', resource: '' };
}

if (uri.port === '') {
uri.port = (uri.protocol.toLowerCase() === 'http' ? '80' : (uri.protocol.toLowerCase() === 'https' ? '443' : ''));
}
var scheme = parts[1].toLowerCase();
var uri = {
host: parts[2],
port: parts[3] || (scheme === 'http' ? '80' : (scheme === 'https' ? '443' : '')),
resource: parts[4]
};

return uri;
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "hawk",
"description": "HTTP Hawk Authentication Scheme",
"version": "3.1.0",
"version": "3.1.1",
"author": "Eran Hammer <[email protected]> (http://hueniverse.com)",
"contributors": [],
"repository": "git://github.com/hueniverse/hawk",
Expand Down
Loading

0 comments on commit 10daa13

Please sign in to comment.