allow any url for new request, but still reject non-http url in fetch

This commit is contained in:
David Frank 2016-05-26 02:19:16 +08:00
parent a2607719ce
commit 2a6e656c1d
3 changed files with 14 additions and 8 deletions

View File

@ -56,6 +56,14 @@ function Fetch(url, opts) {
return;
}
if (!options.protocol || !options.hostname) {
throw new Error('only absolute urls are supported');
}
if (options.protocol !== 'http:' && options.protocol !== 'https:') {
throw new Error('only http(s) protocols are supported');
}
var send;
if (options.protocol === 'https:') {
send = https.request;

View File

@ -31,14 +31,6 @@ function Request(input, init) {
url_parsed = parse_url(url);
}
if (!url_parsed.protocol || !url_parsed.hostname) {
throw new Error('only absolute urls are supported');
}
if (url_parsed.protocol !== 'http:' && url_parsed.protocol !== 'https:') {
throw new Error('only http(s) protocols are supported');
}
// normalize init
init = init || {};

View File

@ -1307,6 +1307,12 @@ describe('node-fetch', function() {
});
});
it('should support arbitrary url in Request constructor', function() {
url = 'anything';
var req = new Request(url);
expect(req.url).to.equal('anything');
});
it('should support clone() method in Request constructor', function() {
url = base;
var body = resumer().queue('a=1').end();