Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function check(request) {

const server = http.createServer(function(request, response) {
// run the check function
check.call(this, request, response);
check(request);
response.writeHead(200, {});
response.end('ok');
server.close();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-url.parse-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function check(request) {

const server = http.createServer(function(request, response) {
// run the check function
check.call(this, request, response);
check(request);
response.writeHead(200, {});
response.end('ok');
server.close();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-url.parse-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function check(request) {

const server = http.createServer(function(request, response) {
// run the check function
check.call(this, request, response);
check(request);
response.writeHead(200, {});
response.end('ok');
server.close();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-url.parse-https.request.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function check(request) {

const server = https.createServer(httpsOptions, function(request, response) {
// run the check function
check.call(this, request, response);
check(request);
response.writeHead(200, {});
response.end('ok');
server.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,68 +20,25 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
require('../common');
const assert = require('assert');
const common = require('../common');
const http = require('http');
const url = require('url');


assert.throws(function() {
http.request(url.parse('file:///whatever'));
}, function(err) {
if (err instanceof Error) {
assert.strictEqual(
err.message, 'Protocol "file:" not supported. Expected "http:"');
return true;
}
});

assert.throws(function() {
http.request(url.parse('mailto:asdf@asdf.com'));
}, function(err) {
if (err instanceof Error) {
assert.strictEqual(
err.message, 'Protocol "mailto:" not supported. Expected "http:"');
return true;
}
});

assert.throws(function() {
http.request(url.parse('ftp://www.example.com'));
}, function(err) {
if (err instanceof Error) {
assert.strictEqual(
err.message, 'Protocol "ftp:" not supported. Expected "http:"');
return true;
}
});

assert.throws(function() {
http.request(url.parse('javascript:alert(\'hello\');'));
}, function(err) {
if (err instanceof Error) {
assert.strictEqual(
err.message, 'Protocol "javascript:" not supported. Expected "http:"');
return true;
}
});

assert.throws(function() {
http.request(url.parse('xmpp:isaacschlueter@jabber.org'));
}, function(err) {
if (err instanceof Error) {
assert.strictEqual(
err.message, 'Protocol "xmpp:" not supported. Expected "http:"');
return true;
}
});

assert.throws(function() {
http.request(url.parse('f://some.host/path'));
}, function(err) {
if (err instanceof Error) {
assert.strictEqual(
err.message, 'Protocol "f:" not supported. Expected "http:"');
return true;
}
const invalidUrls = [
'file:///whatever',
'mailto:asdf@asdf.com',
'ftp://www.example.com',
'javascript:alert(\'hello\');',
'xmpp:foo@bar.com',
'f://some.host/path'
];

invalidUrls.forEach((invalid) => {
common.expectsError(
() => { http.request(url.parse(invalid)); },
{
code: 'ERR_INVALID_PROTOCOL',
type: Error
}
);
});
2 changes: 1 addition & 1 deletion test/parallel/test-http-url.parse-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function check(request) {

const server = http.createServer(function(request, response) {
// run the check function
check.call(this, request, response);
check(request);
response.writeHead(200, {});
response.end('ok');
server.close();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-url.parse-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function check(request) {

const server = http.createServer(function(request, response) {
// run the check function
check.call(this, request, response);
check(request);
response.writeHead(200, {});
response.end('ok');
server.close();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-url.parse-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function check(request) {

const server = http.createServer(function(request, response) {
// run the check function
check.call(this, request, response);
check(request);
response.writeHead(200, {});
response.end('ok');
server.close();
Expand Down