mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
http2: make early hints generic
PR-URL: https://github.com/nodejs/node/pull/44820 Fixes: https://github.com/nodejs/node/issues/44816 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
This commit is contained in:
parent
aacd742e91
commit
37f1e4bf4f
11 changed files with 322 additions and 167 deletions
|
@ -403,9 +403,13 @@ function validateUnion(value, name, union) {
|
|||
}
|
||||
}
|
||||
|
||||
function validateLinkHeaderValue(value, name) {
|
||||
const linkValueRegExp = /^(?:<[^>]*>;)\s*(?:rel=(")?[^;"]*\1;?)\s*(?:(?:as|anchor|title)=(")?[^;"]*\2)?$/;
|
||||
const linkValueRegExp = /^(?:<[^>]*>;)\s*(?:rel=(")?[^;"]*\1;?)\s*(?:(?:as|anchor|title)=(")?[^;"]*\2)?$/;
|
||||
|
||||
/**
|
||||
* @param {any} value
|
||||
* @param {string} name
|
||||
*/
|
||||
function validateLinkHeaderFormat(value, name) {
|
||||
if (
|
||||
typeof value === 'undefined' ||
|
||||
!RegExpPrototypeExec(linkValueRegExp, value)
|
||||
|
@ -424,6 +428,42 @@ const validateInternalField = hideStackFrames((object, fieldKey, className) => {
|
|||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {any} hints
|
||||
* @return {string}
|
||||
*/
|
||||
function validateLinkHeaderValue(hints) {
|
||||
if (typeof hints === 'string') {
|
||||
validateLinkHeaderFormat(hints, 'hints');
|
||||
return hints;
|
||||
} else if (ArrayIsArray(hints)) {
|
||||
const hintsLength = hints.length;
|
||||
let result = '';
|
||||
|
||||
if (hintsLength === 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
for (let i = 0; i < hintsLength; i++) {
|
||||
const link = hints[i];
|
||||
validateLinkHeaderFormat(link, 'hints');
|
||||
result += link;
|
||||
|
||||
if (i !== hintsLength - 1) {
|
||||
result += ', ';
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
throw new ERR_INVALID_ARG_VALUE(
|
||||
'hints',
|
||||
hints,
|
||||
'must be an array or string of format "</styles.css>; rel=preload; as=style"'
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
isInt32,
|
||||
isUint32,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue