UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

100 lines (99 loc) • 3.33 kB
import { t as __commonJSMin } from "./chunk-DORXReHP.js"; //#region node_modules/content-type/index.js /*! * content-type * Copyright(c) 2015 Douglas Christopher Wilson * MIT Licensed */ var require_content_type = /* @__PURE__ */ __commonJSMin(((exports) => { /** * RegExp to match *( ";" parameter ) in RFC 7231 sec 3.1.1.1 * * parameter = token "=" ( token / quoted-string ) * token = 1*tchar * tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" * / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" * / DIGIT / ALPHA * ; any VCHAR, except delimiters * quoted-string = DQUOTE *( qdtext / quoted-pair ) DQUOTE * qdtext = HTAB / SP / %x21 / %x23-5B / %x5D-7E / obs-text * obs-text = %x80-FF * quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text ) */ var PARAM_REGEXP = /; *([!#$%&'*+.^_`|~0-9A-Za-z-]+) *= *("(?:[\u000b\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u000b\u0020-\u00ff])*"|[!#$%&'*+.^_`|~0-9A-Za-z-]+) */g; /** * RegExp to match quoted-pair in RFC 7230 sec 3.2.6 * * quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text ) * obs-text = %x80-FF */ var QESC_REGEXP = /\\([\u000b\u0020-\u00ff])/g; /** * RegExp to match type in RFC 7231 sec 3.1.1.1 * * media-type = type "/" subtype * type = token * subtype = token */ var TYPE_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/; exports.parse = parse; /** * Parse media type to object. * * @param {string|object} string * @return {Object} * @public */ function parse(string) { if (!string) throw new TypeError("argument string is required"); var header = typeof string === "object" ? getcontenttype(string) : string; if (typeof header !== "string") throw new TypeError("argument string is required to be a string"); var index = header.indexOf(";"); var type = index !== -1 ? header.slice(0, index).trim() : header.trim(); if (!TYPE_REGEXP.test(type)) throw new TypeError("invalid media type"); var obj = new ContentType(type.toLowerCase()); if (index !== -1) { var key; var match; var value; PARAM_REGEXP.lastIndex = index; while (match = PARAM_REGEXP.exec(header)) { if (match.index !== index) throw new TypeError("invalid parameter format"); index += match[0].length; key = match[1].toLowerCase(); value = match[2]; if (value.charCodeAt(0) === 34) { value = value.slice(1, -1); if (value.indexOf("\\") !== -1) value = value.replace(QESC_REGEXP, "$1"); } obj.parameters[key] = value; } if (index !== header.length) throw new TypeError("invalid parameter format"); } return obj; } /** * Get content-type from req/res objects. * * @param {object} * @return {Object} * @private */ function getcontenttype(obj) { var header; if (typeof obj.getHeader === "function") header = obj.getHeader("content-type"); else if (typeof obj.headers === "object") header = obj.headers && obj.headers["content-type"]; if (typeof header !== "string") throw new TypeError("content-type header is missing from object"); return header; } /** * Class to represent a content type. * @private */ function ContentType(type) { this.parameters = Object.create(null); this.type = type; } })); //#endregion export { require_content_type as t };