allow any url for new request, but still reject non-http url in fetch
This commit is contained in:
parent
a2607719ce
commit
2a6e656c1d
8
index.js
8
index.js
|
@ -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;
|
||||
|
|
|
@ -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 || {};
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue