fetch-to-node
Version:
Node.js-compatible request and response objects for WinterTC runtimes
29 lines (28 loc) • 1.04 kB
JavaScript
/*
* Copyright Michael Hart
* Licensed under the MIT license. See LICENSE file for details.
*
* Portions of this file Copyright Fastly, Inc. See LICENSE file for details.
* Portions of this file Copyright Joyent, Inc. and other Node contributors. See LICENSE file for details.
*/
/* These items copied from Node.js: node/lib/_http_common.js. */
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
*/
export function checkIsHttpToken(val) {
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
*/
export function checkInvalidHeaderChar(val) {
return headerCharRegex.test(val);
}
export const chunkExpression = /(?:^|\W)chunked(?:$|\W)/i;