跳转到内容
搜索文档

更新日志

Cloudflare 的最新更新与改进。

Back to all posts

Workers fetch 请求现在支持 cf.vary

Workers fetch() 请求现在支持 cf.vary 请求选项。使用 cf.vary 可以控制 Cloudflare 如何为单个子请求缓存具有 Vary 标头的源服务器响应。

src/index.jsjs
export default {
	async fetch(request) {
		return fetch(request, {
			cf: {
				vary: {
					default: { action: "bypass" },
					headers: {
						accept: {
							action: "normalize",
							media_types: ["text/html", "application/json"],
						},
						"accept-language": {
							action: "normalize",
							languages: ["en", "fr", "de"],
						},
					},
				},
			},
		});
	},
};
src/index.tsts
export default {
	async fetch(request): Promise<Response> {
		return fetch(request, {
			cf: {
				vary: {
					default: { action: "bypass" },
					headers: {
						accept: {
							action: "normalize",
							media_types: ["text/html", "application/json"],
						},
						"accept-language": {
							action: "normalize",
							languages: ["en", "fr", "de"],
						},
					},
				},
			},
		});
	},
} satisfies ExportedHandler;

有关更多信息,请参阅 cf.vary