зеркало из https://github.com/mozilla/hawk.git
closes #72
This commit is contained in:
Родитель
918f362291
Коммит
637cf3aa38
|
@ -42,7 +42,14 @@ exports.parseHost = function (req, hostHeaderName) {
|
|||
return null;
|
||||
}
|
||||
|
||||
var hostHeaderRegex = /^(?:(?:\r\n)?[\t ])*([^:]+)(?::(\d+))?(?:(?:\r\n)?[\t ])*$/; // Does not support IPv6
|
||||
var hostHeaderRegex;
|
||||
if (hostHeader[0] === '[') {
|
||||
hostHeaderRegex = /^(?:(?:\r\n)?\s)*(\[[^\]]+\])(?::(\d+))?(?:(?:\r\n)?\s)*$/;
|
||||
}
|
||||
else {
|
||||
hostHeaderRegex = /^(?:(?:\r\n)?\s)*([^:]+)(?::(\d+))?(?:(?:\r\n)?\s)*$/;
|
||||
}
|
||||
|
||||
var hostParts = hostHeader.match(hostHeaderRegex);
|
||||
|
||||
if (!hostParts ||
|
||||
|
|
|
@ -57,6 +57,44 @@ describe('Hawk', function () {
|
|||
expect(Hawk.utils.parseHost(req, 'Host').port).to.equal(443);
|
||||
done();
|
||||
});
|
||||
|
||||
it('returns port 443 for non tls node request (IPv6)', function (done) {
|
||||
|
||||
var req = {
|
||||
method: 'POST',
|
||||
url: '/resource/4?filter=a',
|
||||
headers: {
|
||||
host: '[123:123:123]',
|
||||
'content-type': 'text/plain;x=y'
|
||||
},
|
||||
connection: {
|
||||
encrypted: true
|
||||
}
|
||||
};
|
||||
|
||||
expect(Hawk.utils.parseHost(req, 'Host').port).to.equal(443);
|
||||
done();
|
||||
});
|
||||
|
||||
it('parses IPv6 headers', function (done) {
|
||||
|
||||
var req = {
|
||||
method: 'POST',
|
||||
url: '/resource/4?filter=a',
|
||||
headers: {
|
||||
host: '[123:123:123]:8000',
|
||||
'content-type': 'text/plain;x=y'
|
||||
},
|
||||
connection: {
|
||||
encrypted: true
|
||||
}
|
||||
};
|
||||
|
||||
var host = Hawk.utils.parseHost(req, 'Host');
|
||||
expect(host.port).to.equal('8000');
|
||||
expect(host.name).to.equal('[123:123:123]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#version', function () {
|
||||
|
|
Загрузка…
Ссылка в новой задаче