/** * @file 域名缓存规则相关逻辑 * @desc 详见 https://github.com/qbox/mikud/blob/main/docs/httpdns.md */ /** 对 path 的重写规则 */ export type CacheKeyRewrite = { /** 匹配规则(正则表达式字符串) */ pattern: string; /** * 重写替换,如: * 匹配规则:`/w/(\d+)/(\d+)/(.*)` ,重写替换:`/${3}?imageView/2/w/${1}`; * 结果:`/w/300/200/apple` 会被替换为 `/apple?imageView/2/w/300` */ repl: string; }; /** 对 query string 的转换规则 */ export type CacheKeyQueryStringConfig = { /** * 对 query string 的处理方式 * - `none` 表示所有 query string 不包含在 cache key 中 * - `include` 表示指定 query string 包含在 cache key 中 * - `exclude` 表示指定 query string 不包含在 cache key 中,其他都包含 * - `all` 表示所有 query string 都包含在 cache key 中 */ type: 'none' | 'include' | 'exclude' | 'all'; /** 在 `type` 为 `include` 或者 `exclude` 时,指定要被 include 或 exclude 的参数名 */ values?: string[]; }; /** * 缓存 Key 生成规则。 * 详见 https://github.com/qbox/miku/issues/338#issuecomment-1421896955 */ export type CacheKeyConfig = { /** 对 path 的重写规则 */ rewrites: CacheKeyRewrite[]; /** 对 query string 的转换规则 */ queryString: CacheKeyQueryStringConfig; }; export declare function getCacheKey( /** 请求原 URL */ url: string, /** 缓存 Key 生成规则 */ cacheKeyConfig: CacheKeyConfig, /** bucket ID,值可能为空字符串,代表没有 bucket ID */ bucket: string): string; export declare function applyRewrites(rewrites: CacheKeyRewrite[], path: string): string; export declare function applyQueryStringConfig({ type, values }: CacheKeyQueryStringConfig, querystring: string): string;