summaryrefslogtreecommitdiff
path: root/test/parallel/test-http2-respond-file-fd-errors.js
diff options
context:
space:
mode:
authorAnatoli Papirovski <apapirovski@mac.com>2017-09-30 10:06:21 -0400
committerRuben Bridgewater <ruben@bridgewater.de>2017-10-01 20:14:10 -0300
commitccd3afc84303247b32c011fea7630d150f07849d (patch)
treef010f7b450075412a57e74c29f05a23e15d7d60e /test/parallel/test-http2-respond-file-fd-errors.js
parentdcd890a1355c8b4165d631155048051ddd2d83f3 (diff)
downloadandroid-node-v8-ccd3afc84303247b32c011fea7630d150f07849d.tar.gz
android-node-v8-ccd3afc84303247b32c011fea7630d150f07849d.tar.bz2
android-node-v8-ccd3afc84303247b32c011fea7630d150f07849d.zip
http2: adjust error emit in core, add tests
Use the ability of nextTick and setImmediate to pass arguments instead of creating closures or binding. Add tests that cover the vast majority of error emits. PR-URL: https://github.com/nodejs/node/pull/15586 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'test/parallel/test-http2-respond-file-fd-errors.js')
-rw-r--r--test/parallel/test-http2-respond-file-fd-errors.js40
1 files changed, 35 insertions, 5 deletions
diff --git a/test/parallel/test-http2-respond-file-fd-errors.js b/test/parallel/test-http2-respond-file-fd-errors.js
index faf37f3373..95c4b5fea6 100644
--- a/test/parallel/test-http2-respond-file-fd-errors.js
+++ b/test/parallel/test-http2-respond-file-fd-errors.js
@@ -7,6 +7,11 @@ const http2 = require('http2');
const path = require('path');
const fs = require('fs');
+const {
+ HTTP2_HEADER_CONTENT_TYPE,
+ HTTP2_HEADER_METHOD
+} = http2.constants;
+
const optionsWithTypeError = {
offset: 'number',
length: 'number',
@@ -38,7 +43,7 @@ server.on('stream', common.mustCall((stream) => {
common.expectsError(
() => stream.respondWithFD(types[type], {
- [http2.constants.HTTP2_HEADER_CONTENT_TYPE]: 'text/plain'
+ [HTTP2_HEADER_CONTENT_TYPE]: 'text/plain'
}),
{
type: TypeError,
@@ -57,7 +62,7 @@ server.on('stream', common.mustCall((stream) => {
common.expectsError(
() => stream.respondWithFD(fd, {
- [http2.constants.HTTP2_HEADER_CONTENT_TYPE]: 'text/plain'
+ [HTTP2_HEADER_CONTENT_TYPE]: 'text/plain'
}, {
[option]: types[type]
}),
@@ -74,25 +79,49 @@ server.on('stream', common.mustCall((stream) => {
// Should throw if :status 204, 205 or 304
[204, 205, 304].forEach((status) => common.expectsError(
() => stream.respondWithFD(fd, {
- [http2.constants.HTTP2_HEADER_CONTENT_TYPE]: 'text/plain',
+ [HTTP2_HEADER_CONTENT_TYPE]: 'text/plain',
':status': status,
}),
{
code: 'ERR_HTTP2_PAYLOAD_FORBIDDEN',
+ type: Error,
message: `Responses with ${status} status must not have a payload`
}
));
+ // should emit an error on the stream if headers aren't valid
+ stream.respondWithFD(fd, {
+ [HTTP2_HEADER_METHOD]: 'POST'
+ }, {
+ statCheck() {
+ return true;
+ }
+ });
+ stream.once('error', common.expectsError({
+ code: 'ERR_HTTP2_INVALID_PSEUDOHEADER',
+ type: Error,
+ message: '":method" is an invalid pseudoheader or is used incorrectly'
+ }));
+ stream.respondWithFD(fd, {
+ [HTTP2_HEADER_METHOD]: 'POST'
+ });
+ stream.once('error', common.expectsError({
+ code: 'ERR_HTTP2_INVALID_PSEUDOHEADER',
+ type: Error,
+ message: '":method" is an invalid pseudoheader or is used incorrectly'
+ }));
+
// Should throw if headers already sent
stream.respond({
':status': 200,
});
common.expectsError(
() => stream.respondWithFD(fd, {
- [http2.constants.HTTP2_HEADER_CONTENT_TYPE]: 'text/plain'
+ [HTTP2_HEADER_CONTENT_TYPE]: 'text/plain'
}),
{
code: 'ERR_HTTP2_HEADERS_SENT',
+ type: Error,
message: 'Response has already been initiated.'
}
);
@@ -101,10 +130,11 @@ server.on('stream', common.mustCall((stream) => {
stream.destroy();
common.expectsError(
() => stream.respondWithFD(fd, {
- [http2.constants.HTTP2_HEADER_CONTENT_TYPE]: 'text/plain'
+ [HTTP2_HEADER_CONTENT_TYPE]: 'text/plain'
}),
{
code: 'ERR_HTTP2_INVALID_STREAM',
+ type: Error,
message: 'The stream has been destroyed'
}
);