小编Mar*_*app的帖子

返回304 Not Modified with ServiceStack时防止不需要的标头

使用ServiceStack,我只想返回304 Not Modified:

HTTP/1.1 304 Not Modified
Run Code Online (Sandbox Code Playgroud)

但ServiceStack添加了许多其他不需要的(返回带有304代码的HttpResult)标头:

HTTP/1.1 304 Not Modified
Content-Length: 0
Content-Type: application/json
Server: Microsoft-HTTPAPI/2.0
X-Powered-By: ServiceStack/3.94 Win32NT/.NET
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Headers: Content-Type
Date: Tue, 07 Aug 2012 13:39:19 GMT
Run Code Online (Sandbox Code Playgroud)

如何防止输出其他标题?我已经尝试了HttpResult的各种方法,注册了一个虚拟内容类型过滤器,但是它的名字仅暗示控件内容,而不是标题或此处列出的其他内容.我也尝试使用IStreamWriter和IHasOptions实现我自己的IHttpResult派生,结果相同:ServiceStack添加了不需要的标头.

谢谢

更新

能够去除content-type通过使用以下,但有些头依然存在,即content-length,serverdate.

    public override object OnGet(FaultTypes request)
    {
      var result = new HttpResult
      {
       StatusCode = HttpStatusCode.NotModified,
       StatusDescription = "Not Modified", // Otherwise NotModified written!
      }; …
Run Code Online (Sandbox Code Playgroud)

http-status-code-304 servicestack

6
推荐指数
1
解决办法
2350
查看次数

标签 统计

http-status-code-304 ×1

servicestack ×1