servicestack 当HTTP状态代码为204无内容时,为什么ServiceStack不添加CORS头?,servicestack,cors,servicestack,Cors" /> servicestack 当HTTP状态代码为204无内容时,为什么ServiceStack不添加CORS头?,servicestack,cors,servicestack,Cors" />

servicestack 当HTTP状态代码为204无内容时,为什么ServiceStack不添加CORS头?

servicestack 当HTTP状态代码为204无内容时,为什么ServiceStack不添加CORS头?,servicestack,cors,servicestack,Cors,当HTTP状态代码为204无内容时,ServiceStack为什么不添加CORS头?刚刚用最新版本的ServiceStack测试了这一点: 将ServiceStack配置为对null或void响应返回204 NoContent: SetConfig(new HostConfig { Return204NoContentForEmptyResponse = true, }); [Route("/void-response")] public class TestVoidResponse

当HTTP状态代码为204无内容时,ServiceStack为什么不添加CORS头?

刚刚用最新版本的ServiceStack测试了这一点:

将ServiceStack配置为对
null
void
响应返回204 NoContent

SetConfig(new HostConfig {
    Return204NoContentForEmptyResponse = true,
});
[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;
    }
}
添加自定义CORS配置:

Plugins.Add(new CorsFeature(
    allowCredentials: true,
    allowedHeaders: "Content-Type, Allow, Authorization"));
添加返回
void
null
响应的新服务:

SetConfig(new HostConfig {
    Return204NoContentForEmptyResponse = true,
});
[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;
    }
}
请致电上述服务:

两个服务都返回带有CORS标题的204 NoContent:

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