gpt4 book ai didi

apache - 从 Apache 返回空响应

转载 作者:行者123 更新时间:2023-12-04 00:13:22 26 4
gpt4 key购买 nike

我正在使用 Apache 返回 CORS 响应以加速请求(以前我在应用程序代码中处理过这个,但这太慢了)。在我的 VirtualHost 中,我有以下 Apache 代码:

SetEnvIfNoCase Access-Control-Request-Method "(GET|POST|PUT|DELETE|OPTIONS)" IsPreflight=1
SetEnvIfNoCase Origin "http(s)?://(myorigin.com)$" AccessControlAllowOrigin=$0$1

Header always set Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
Header always set Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS" env=IsPreflight
Header always set Access-Control-Allow-Headers "Content-Type, Authorization, Accept" env=IsPreflight
Header always set Access-Control-Max-Age "7200" env=IsPreflight

RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteCond %{ENV:IsPreflight} 1
RewriteRule ^(.*)$ $1 [R=200,L]

这实际上非常有效。它检测请求是否是预检请求,如果是,则发送适当的 header 。只有一个问题:预检请求返回200(所以浏览器发送正常请求),但正文是200 ERROR(哈哈):
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>200 OK</title>
</head><body>
<h1>OK</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator at
you@example.com to inform them of the time this error occurred,
and the actions you performed just before this error.</p>
<p>More information about this error may be available
in the server error log.</p>
</body></html>

虽然这可以正常工作,但我想从预检正文中删除这个丑陋的错误,但我没有找到任何方法告诉 Apache 实际返回一个空正文。

谢谢!

最佳答案

OPTIONS 请求的 204 代码(无内容)响应。

例如:

RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=204,L]

关于apache - 从 Apache 返回空响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27703871/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com