为什么 ServiceStack 在 HTTP 状态码为 204 No Content 时不添加 CORS headers?
Why does ServiceStack not add the CORS headers when the HTTP status code is 204 No Content?
为什么在HTTP状态码为204[时ServiceStack不添加CORSheaders =16=]没有内容?
刚刚使用最新版本的 ServiceStack 对此进行了测试:
将 ServiceStack 配置为 return 204 NoContent null
或 void
响应:
SetConfig(new HostConfig {
Return204NoContentForEmptyResponse = true,
});
添加自定义 CORS 配置:
Plugins.Add(new CorsFeature(
allowCredentials: true,
allowedHeaders: "Content-Type, Allow, Authorization"));
添加新服务 returning void
和 null
响应:
[Route("/void-response")]
public class TestVoidResponse { }
[Route("/null-response")]
public class TestNullResponse { }
public class TestServices : Service
{
public void Any(TestVoidResponse response) {}
public object Any(TestNullResponse response)
{
return null;
}
}
调用以上服务:
两种服务 return 204 NoContent 与 CORS Headers:
HTTP/1.1 204 No Content
Cache-Control: private
Content-Length: 0
Vary: Accept
Server: Microsoft-IIS/8.5
X-Powered-By: ServiceStack/4.00 Win32NT/.NET
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Headers: Content-Type, Allow, Authorization
Access-Control-Allow-Credentials: true
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Thu, 19 Feb 2015 15:10:50 GMT
为什么在HTTP状态码为204[时ServiceStack不添加CORSheaders =16=]没有内容?
刚刚使用最新版本的 ServiceStack 对此进行了测试:
将 ServiceStack 配置为 return 204 NoContent null
或 void
响应:
SetConfig(new HostConfig {
Return204NoContentForEmptyResponse = true,
});
添加自定义 CORS 配置:
Plugins.Add(new CorsFeature(
allowCredentials: true,
allowedHeaders: "Content-Type, Allow, Authorization"));
添加新服务 returning void
和 null
响应:
[Route("/void-response")]
public class TestVoidResponse { }
[Route("/null-response")]
public class TestNullResponse { }
public class TestServices : Service
{
public void Any(TestVoidResponse response) {}
public object Any(TestNullResponse response)
{
return null;
}
}
调用以上服务:
两种服务 return 204 NoContent 与 CORS Headers:
HTTP/1.1 204 No Content
Cache-Control: private
Content-Length: 0
Vary: Accept
Server: Microsoft-IIS/8.5
X-Powered-By: ServiceStack/4.00 Win32NT/.NET
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Headers: Content-Type, Allow, Authorization
Access-Control-Allow-Credentials: true
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Thu, 19 Feb 2015 15:10:50 GMT