0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-http-outgoing-proto.js
Brian White 61ebfa8d1f tools: add unescaped regexp dot rule to linter
PR-URL: https://github.com/nodejs/node/pull/11834
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
2017-03-29 10:53:28 +02:00

76 lines
2.6 KiB
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const http = require('http');
const OutgoingMessage = http.OutgoingMessage;
const ClientRequest = http.ClientRequest;
const ServerResponse = http.ServerResponse;
assert.throws(OutgoingMessage.prototype._implicitHeader,
/^Error: _implicitHeader\(\) method is not implemented$/);
assert.strictEqual(
typeof ClientRequest.prototype._implicitHeader, 'function');
assert.strictEqual(
typeof ServerResponse.prototype._implicitHeader, 'function');
// validateHeader
assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.setHeader();
}, /^TypeError: Header name must be a valid HTTP Token \["undefined"\]$/);
assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.setHeader('test');
}, /^Error: "value" required in setHeader\("test", value\)$/);
assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.setHeader(404);
}, /^TypeError: Header name must be a valid HTTP Token \["404"\]$/);
assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.setHeader.call({_header: 'test'}, 'test', 'value');
}, /^Error: Can't set headers after they are sent\.$/);
assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.setHeader('200', 'あ');
}, /^TypeError: The header content contains invalid characters$/);
// write
assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.write();
}, /^Error: _implicitHeader\(\) method is not implemented$/);
assert(OutgoingMessage.prototype.write.call({_header: 'test'}));
assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.write.call({_header: 'test', _hasBody: 'test'});
}, /^TypeError: First argument must be a string or Buffer$/);
assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.write.call({_header: 'test', _hasBody: 'test'}, 1);
}, /^TypeError: First argument must be a string or Buffer$/);
// addTrailers
assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.addTrailers();
}, /^TypeError: Cannot convert undefined or null to object$/);
assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.addTrailers({'あ': 'value'});
}, /^TypeError: Trailer name must be a valid HTTP Token \["あ"\]$/);
assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.addTrailers({404: 'あ'});
}, /^TypeError: The trailer content contains invalid characters$/);