2016-08-02 18:28:38 +02:00
|
|
|
'use strict';
|
2020-02-22 12:28:26 +01:00
|
|
|
require('../common');
|
2016-08-02 18:28:38 +02:00
|
|
|
const assert = require('assert');
|
|
|
|
|
|
|
|
const http = require('http');
|
|
|
|
const OutgoingMessage = http.OutgoingMessage;
|
|
|
|
const ClientRequest = http.ClientRequest;
|
|
|
|
const ServerResponse = http.ServerResponse;
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
typeof ClientRequest.prototype._implicitHeader, 'function');
|
|
|
|
assert.strictEqual(
|
|
|
|
typeof ServerResponse.prototype._implicitHeader, 'function');
|
2017-01-15 17:39:25 +01:00
|
|
|
|
|
|
|
// validateHeader
|
2019-12-25 18:02:16 +01:00
|
|
|
assert.throws(() => {
|
2017-01-15 17:39:25 +01:00
|
|
|
const outgoingMessage = new OutgoingMessage();
|
|
|
|
outgoingMessage.setHeader();
|
2017-12-08 22:41:38 +01:00
|
|
|
}, {
|
2017-08-10 12:58:22 +02:00
|
|
|
code: 'ERR_INVALID_HTTP_TOKEN',
|
2019-12-25 18:02:16 +01:00
|
|
|
name: 'TypeError',
|
2017-08-10 12:58:22 +02:00
|
|
|
message: 'Header name must be a valid HTTP token ["undefined"]'
|
2017-12-08 22:41:38 +01:00
|
|
|
});
|
2017-01-15 17:39:25 +01:00
|
|
|
|
2019-12-25 18:02:16 +01:00
|
|
|
assert.throws(() => {
|
2017-01-15 17:39:25 +01:00
|
|
|
const outgoingMessage = new OutgoingMessage();
|
|
|
|
outgoingMessage.setHeader('test');
|
2017-12-08 22:41:38 +01:00
|
|
|
}, {
|
2017-11-03 13:04:12 +01:00
|
|
|
code: 'ERR_HTTP_INVALID_HEADER_VALUE',
|
2019-12-25 18:02:16 +01:00
|
|
|
name: 'TypeError',
|
2017-11-03 13:04:12 +01:00
|
|
|
message: 'Invalid value "undefined" for header "test"'
|
2017-12-08 22:41:38 +01:00
|
|
|
});
|
2017-01-15 17:39:25 +01:00
|
|
|
|
2019-12-25 18:02:16 +01:00
|
|
|
assert.throws(() => {
|
2017-01-15 17:39:25 +01:00
|
|
|
const outgoingMessage = new OutgoingMessage();
|
|
|
|
outgoingMessage.setHeader(404);
|
2017-12-08 22:41:38 +01:00
|
|
|
}, {
|
2017-08-10 12:58:22 +02:00
|
|
|
code: 'ERR_INVALID_HTTP_TOKEN',
|
2019-12-25 18:02:16 +01:00
|
|
|
name: 'TypeError',
|
2017-08-10 12:58:22 +02:00
|
|
|
message: 'Header name must be a valid HTTP token ["404"]'
|
2017-12-08 22:41:38 +01:00
|
|
|
});
|
2017-01-15 17:39:25 +01:00
|
|
|
|
2019-12-25 18:02:16 +01:00
|
|
|
assert.throws(() => {
|
2017-01-15 17:39:25 +01:00
|
|
|
const outgoingMessage = new OutgoingMessage();
|
2017-07-11 02:55:21 +02:00
|
|
|
outgoingMessage.setHeader.call({ _header: 'test' }, 'test', 'value');
|
2017-12-08 22:41:38 +01:00
|
|
|
}, {
|
2017-08-10 12:58:22 +02:00
|
|
|
code: 'ERR_HTTP_HEADERS_SENT',
|
2019-12-25 18:02:16 +01:00
|
|
|
name: 'Error',
|
2017-08-10 12:58:22 +02:00
|
|
|
message: 'Cannot set headers after they are sent to the client'
|
2017-12-08 22:41:38 +01:00
|
|
|
});
|
2017-01-15 17:39:25 +01:00
|
|
|
|
2019-12-25 18:02:16 +01:00
|
|
|
assert.throws(() => {
|
2017-01-15 17:39:25 +01:00
|
|
|
const outgoingMessage = new OutgoingMessage();
|
|
|
|
outgoingMessage.setHeader('200', 'あ');
|
2017-12-08 22:41:38 +01:00
|
|
|
}, {
|
2017-08-10 12:58:22 +02:00
|
|
|
code: 'ERR_INVALID_CHAR',
|
2019-12-25 18:02:16 +01:00
|
|
|
name: 'TypeError',
|
2017-08-10 12:58:22 +02:00
|
|
|
message: 'Invalid character in header content ["200"]'
|
2017-12-08 22:41:38 +01:00
|
|
|
});
|
2017-01-15 17:39:25 +01:00
|
|
|
|
|
|
|
// write
|
2018-02-16 12:53:34 +01:00
|
|
|
{
|
2017-01-15 17:39:25 +01:00
|
|
|
const outgoingMessage = new OutgoingMessage();
|
2018-02-16 12:53:34 +01:00
|
|
|
|
2020-02-22 12:28:26 +01:00
|
|
|
assert.throws(
|
|
|
|
() => {
|
|
|
|
outgoingMessage.write('');
|
|
|
|
},
|
|
|
|
{
|
|
|
|
code: 'ERR_METHOD_NOT_IMPLEMENTED',
|
|
|
|
name: 'Error',
|
|
|
|
message: 'The _implicitHeader() method is not implemented'
|
|
|
|
}
|
|
|
|
);
|
2018-02-16 12:53:34 +01:00
|
|
|
}
|
2017-01-15 17:39:25 +01:00
|
|
|
|
2019-12-25 18:02:16 +01:00
|
|
|
assert.throws(() => {
|
2017-01-15 17:39:25 +01:00
|
|
|
const outgoingMessage = new OutgoingMessage();
|
2017-07-11 02:55:21 +02:00
|
|
|
outgoingMessage.write.call({ _header: 'test', _hasBody: 'test' });
|
2017-12-08 22:41:38 +01:00
|
|
|
}, {
|
2017-08-10 12:58:22 +02:00
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
2019-12-25 18:02:16 +01:00
|
|
|
name: 'TypeError',
|
2020-02-16 10:47:13 +01:00
|
|
|
message: 'The "chunk" argument must be of type string or an instance of ' +
|
|
|
|
'Buffer or Uint8Array. Received undefined'
|
2017-12-08 22:41:38 +01:00
|
|
|
});
|
2017-01-15 17:39:25 +01:00
|
|
|
|
2019-12-25 18:02:16 +01:00
|
|
|
assert.throws(() => {
|
2017-01-15 17:39:25 +01:00
|
|
|
const outgoingMessage = new OutgoingMessage();
|
2017-07-11 02:55:21 +02:00
|
|
|
outgoingMessage.write.call({ _header: 'test', _hasBody: 'test' }, 1);
|
2017-12-08 22:41:38 +01:00
|
|
|
}, {
|
2017-08-10 12:58:22 +02:00
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
2019-12-25 18:02:16 +01:00
|
|
|
name: 'TypeError',
|
2020-02-16 10:47:13 +01:00
|
|
|
message: 'The "chunk" argument must be of type string or an instance of ' +
|
|
|
|
'Buffer or Uint8Array. Received type number (1)'
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.throws(() => {
|
|
|
|
const outgoingMessage = new OutgoingMessage();
|
|
|
|
outgoingMessage.write.call({ _header: 'test', _hasBody: 'test' }, null);
|
|
|
|
}, {
|
|
|
|
code: 'ERR_STREAM_NULL_VALUES',
|
|
|
|
name: 'TypeError'
|
2017-12-08 22:41:38 +01:00
|
|
|
});
|
2017-01-15 17:39:25 +01:00
|
|
|
|
2017-10-18 00:59:41 +02:00
|
|
|
// addTrailers()
|
|
|
|
// The `Error` comes from the JavaScript engine so confirm that it is a
|
|
|
|
// `TypeError` but do not check the message. It will be different in different
|
|
|
|
// JavaScript engines.
|
2017-01-15 17:39:25 +01:00
|
|
|
assert.throws(() => {
|
|
|
|
const outgoingMessage = new OutgoingMessage();
|
|
|
|
outgoingMessage.addTrailers();
|
2017-10-18 00:59:41 +02:00
|
|
|
}, TypeError);
|
2017-01-15 17:39:25 +01:00
|
|
|
|
2019-12-25 18:02:16 +01:00
|
|
|
assert.throws(() => {
|
2017-01-15 17:39:25 +01:00
|
|
|
const outgoingMessage = new OutgoingMessage();
|
2017-07-11 02:55:21 +02:00
|
|
|
outgoingMessage.addTrailers({ 'あ': 'value' });
|
2017-12-08 22:41:38 +01:00
|
|
|
}, {
|
2017-08-10 12:58:22 +02:00
|
|
|
code: 'ERR_INVALID_HTTP_TOKEN',
|
2019-12-25 18:02:16 +01:00
|
|
|
name: 'TypeError',
|
2017-08-10 12:58:22 +02:00
|
|
|
message: 'Trailer name must be a valid HTTP token ["あ"]'
|
2017-12-08 22:41:38 +01:00
|
|
|
});
|
2017-01-15 17:39:25 +01:00
|
|
|
|
2019-12-25 18:02:16 +01:00
|
|
|
assert.throws(() => {
|
2017-01-15 17:39:25 +01:00
|
|
|
const outgoingMessage = new OutgoingMessage();
|
2017-07-11 02:55:21 +02:00
|
|
|
outgoingMessage.addTrailers({ 404: 'あ' });
|
2017-12-08 22:41:38 +01:00
|
|
|
}, {
|
2017-08-10 12:58:22 +02:00
|
|
|
code: 'ERR_INVALID_CHAR',
|
2019-12-25 18:02:16 +01:00
|
|
|
name: 'TypeError',
|
2017-08-10 12:58:22 +02:00
|
|
|
message: 'Invalid character in trailer content ["404"]'
|
2017-12-08 22:41:38 +01:00
|
|
|
});
|
2020-03-08 12:39:50 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
const outgoingMessage = new OutgoingMessage();
|
|
|
|
assert.strictEqual(outgoingMessage.destroyed, false);
|
|
|
|
outgoingMessage.destroy();
|
|
|
|
assert.strictEqual(outgoingMessage.destroyed, true);
|
|
|
|
}
|