Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite4d641f

Browse files
authored
lib: refactor to use validators in http2
Refs:#46101PR-URL:#46174Reviewed-By: Paolo Insogna <paolo@cowtech.it>Reviewed-By: Matteo Collina <matteo.collina@gmail.com>Reviewed-By: Luigi Pinca <luigipinca@gmail.com>Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
1 parente8d4015 commite4d641f

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

‎lib/internal/http2/core.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ const {
126126
validateNumber,
127127
validateString,
128128
validateUint32,
129-
validateAbortSignal
129+
validateAbortSignal,
130+
validateBoolean,
130131
}=require('internal/validators');
131132
constfsPromisesInternal=require('internal/fs/promises');
132133
const{ utcDate}=require('internal/http');
@@ -761,26 +762,26 @@ function requestOnConnect(headers, options) {
761762
constsetAndValidatePriorityOptions=hideStackFrames((options)=>{
762763
if(options.weight===undefined){
763764
options.weight=NGHTTP2_DEFAULT_WEIGHT;
764-
}elseif(typeofoptions.weight!=='number'){
765-
thrownewERR_INVALID_ARG_VALUE('options.weight',options.weight);
765+
}else{
766+
validateNumber(options.weight,'options.weight');
766767
}
767768

768769
if(options.parent===undefined){
769770
options.parent=0;
770-
}elseif(typeofoptions.parent!=='number'||options.parent<0){
771-
thrownewERR_INVALID_ARG_VALUE('options.parent',options.parent);
771+
}else{
772+
validateNumber(options.parent,'options.parent',0);
772773
}
773774

774775
if(options.exclusive===undefined){
775776
options.exclusive=false;
776-
}elseif(typeofoptions.exclusive!=='boolean'){
777-
thrownewERR_INVALID_ARG_VALUE('options.exclusive',options.exclusive);
777+
}else{
778+
validateBoolean(options.exclusive,'options.exclusive');
778779
}
779780

780781
if(options.silent===undefined){
781782
options.silent=false;
782-
}elseif(typeofoptions.silent!=='boolean'){
783-
thrownewERR_INVALID_ARG_VALUE('options.silent',options.silent);
783+
}else{
784+
validateBoolean(options.silent,'options.silent');
784785
}
785786
});
786787

@@ -1784,8 +1785,8 @@ class ClientHttp2Session extends Http2Session {
17841785
// stream by default if the user has not specifically indicated a
17851786
// preference.
17861787
options.endStream=isPayloadMeaningless(headers[HTTP2_HEADER_METHOD]);
1787-
}elseif(typeofoptions.endStream!=='boolean'){
1788-
thrownewERR_INVALID_ARG_VALUE('options.endStream',options.endStream);
1788+
}else{
1789+
validateBoolean(options.endStream,'options.endStream');
17891790
}
17901791

17911792
constheadersList=mapToHeaders(headers);

‎test/parallel/test-http2-client-request-options-errors.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ if (!common.hasCrypto)
55
common.skip('missing crypto');
66
constassert=require('assert');
77
consthttp2=require('http2');
8-
const{ inspect}=require('util');
98

109
// Check if correct errors are emitted when wrong type of data is passed
1110
// to certain options of ClientHttp2Session request method
@@ -48,9 +47,7 @@ server.listen(0, common.mustCall(() => {
4847
[option]:types[type]
4948
}),{
5049
name:'TypeError',
51-
code:'ERR_INVALID_ARG_VALUE',
52-
message:`The property 'options.${option}' is invalid. `+
53-
`Received${inspect(types[type])}`
50+
code:'ERR_INVALID_ARG_TYPE',
5451
});
5552
});
5653
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp