2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-02-14 11:38:45 -05:00
|
|
|
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
|
|
|
|
2023-06-27 02:18:22 -04:00
|
|
|
// TODO(petamoriken): enable prefer-primordials for node polyfills
|
|
|
|
// deno-lint-ignore-file prefer-primordials
|
|
|
|
|
2023-02-14 11:38:45 -05:00
|
|
|
const tokenRegExp = /^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/;
|
|
|
|
/**
|
|
|
|
* Verifies that the given val is a valid HTTP token
|
|
|
|
* per the rules defined in RFC 7230
|
|
|
|
* See https://tools.ietf.org/html/rfc7230#section-3.2.6
|
|
|
|
*/
|
|
|
|
function checkIsHttpToken(val: string) {
|
|
|
|
return tokenRegExp.test(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
const headerCharRegex = /[^\t\x20-\x7e\x80-\xff]/;
|
|
|
|
/**
|
|
|
|
* True if val contains an invalid field-vchar
|
|
|
|
* field-value = *( field-content / obs-fold )
|
|
|
|
* field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
|
|
|
|
* field-vchar = VCHAR / obs-text
|
|
|
|
*/
|
|
|
|
function checkInvalidHeaderChar(val: string) {
|
|
|
|
return headerCharRegex.test(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
export const chunkExpression = /(?:^|\W)chunked(?:$|\W)/i;
|
|
|
|
export {
|
|
|
|
checkInvalidHeaderChar as _checkInvalidHeaderChar,
|
|
|
|
checkIsHttpToken as _checkIsHttpToken,
|
|
|
|
};
|