summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/_http_common.ts
diff options
context:
space:
mode:
Diffstat (limited to 'ext/node/polyfills/_http_common.ts')
-rw-r--r--ext/node/polyfills/_http_common.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/ext/node/polyfills/_http_common.ts b/ext/node/polyfills/_http_common.ts
new file mode 100644
index 000000000..616fbb65d
--- /dev/null
+++ b/ext/node/polyfills/_http_common.ts
@@ -0,0 +1,29 @@
+// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+// Copyright Joyent and Node contributors. All rights reserved. MIT license.
+
+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,
+};