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.
|
|
|
|
|
2024-06-20 03:26:14 -04:00
|
|
|
import { primordials } from "ext:core/mod.js";
|
2024-09-11 20:52:08 -04:00
|
|
|
const {
|
|
|
|
RegExpPrototypeTest,
|
|
|
|
SafeRegExp,
|
|
|
|
Symbol,
|
|
|
|
} = primordials;
|
|
|
|
|
|
|
|
export const CRLF = "\r\n";
|
|
|
|
export const kIncomingMessage = Symbol("IncomingMessage");
|
2024-06-20 03:26:14 -04:00
|
|
|
const tokenRegExp = new SafeRegExp(/^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/);
|
2024-09-11 20:52:08 -04:00
|
|
|
|
|
|
|
export const methods = [
|
|
|
|
"ACL",
|
|
|
|
"BIND",
|
|
|
|
"CHECKOUT",
|
|
|
|
"CONNECT",
|
|
|
|
"COPY",
|
|
|
|
"DELETE",
|
|
|
|
"GET",
|
|
|
|
"HEAD",
|
|
|
|
"LINK",
|
|
|
|
"LOCK",
|
|
|
|
"M-SEARCH",
|
|
|
|
"MERGE",
|
|
|
|
"MKACTIVITY",
|
|
|
|
"MKCALENDAR",
|
|
|
|
"MKCOL",
|
|
|
|
"MOVE",
|
|
|
|
"NOTIFY",
|
|
|
|
"OPTIONS",
|
|
|
|
"PATCH",
|
|
|
|
"POST",
|
|
|
|
"PROPFIND",
|
|
|
|
"PROPPATCH",
|
|
|
|
"PURGE",
|
|
|
|
"PUT",
|
|
|
|
"REBIND",
|
|
|
|
"REPORT",
|
|
|
|
"SEARCH",
|
|
|
|
"SOURCE",
|
|
|
|
"SUBSCRIBE",
|
|
|
|
"TRACE",
|
|
|
|
"UNBIND",
|
|
|
|
"UNLINK",
|
|
|
|
"UNLOCK",
|
|
|
|
"UNSUBSCRIBE",
|
|
|
|
];
|
|
|
|
|
2023-02-14 11:38:45 -05:00
|
|
|
/**
|
|
|
|
* 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) {
|
2024-06-20 03:26:14 -04:00
|
|
|
return RegExpPrototypeTest(tokenRegExp, val);
|
2023-02-14 11:38:45 -05:00
|
|
|
}
|
|
|
|
|
2024-06-20 03:26:14 -04:00
|
|
|
const headerCharRegex = new SafeRegExp(/[^\t\x20-\x7e\x80-\xff]/);
|
2023-02-14 11:38:45 -05:00
|
|
|
/**
|
|
|
|
* 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) {
|
2024-06-20 03:26:14 -04:00
|
|
|
return RegExpPrototypeTest(headerCharRegex, val);
|
2023-02-14 11:38:45 -05:00
|
|
|
}
|
|
|
|
|
2024-06-20 03:26:14 -04:00
|
|
|
export const chunkExpression = new SafeRegExp(/(?:^|\W)chunked(?:$|\W)/i);
|
2024-09-11 20:52:08 -04:00
|
|
|
export const continueExpression = new SafeRegExp(
|
|
|
|
/(?:^|\W)100-continue(?:$|\W)/i,
|
|
|
|
);
|
|
|
|
|
2023-02-14 11:38:45 -05:00
|
|
|
export {
|
|
|
|
checkInvalidHeaderChar as _checkInvalidHeaderChar,
|
|
|
|
checkIsHttpToken as _checkIsHttpToken,
|
|
|
|
};
|
2024-09-11 20:52:08 -04:00
|
|
|
|
|
|
|
export default {
|
|
|
|
_checkInvalidHeaderChar: checkInvalidHeaderChar,
|
|
|
|
_checkIsHttpToken: checkIsHttpToken,
|
|
|
|
chunkExpression,
|
|
|
|
CRLF,
|
|
|
|
continueExpression,
|
|
|
|
kIncomingMessage,
|
|
|
|
methods,
|
|
|
|
};
|