Using ServiceStack, I just want to return 304 Not Modified as such:
HTTP/1.1 304 Not Modified
But ServiceStack adds many other unwanted (returning HttpResult with 304 code) headers as such:
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
How can I prevent the other headers from being outputted? I've tried various approaches with HttpResult, registering a dummy content type filter, but as its name implies only controls content, not the headers, or others listed here. I've also tried implementing my own IHttpResult derivative with IStreamWriter and IHasOptions with the same results: ServiceStack adds unwanted headers.
Thanks
Update
Was able to remove content-type
by using the following, but some headers are still present i.e. content-length
, server
, and date
.
public override object OnGet(FaultTypes request)
{
var result = new HttpResult
{
StatusCode = HttpStatusCode.NotModified,
StatusDescription = "Not Modified", // Otherwise NotModified written!
};
// The following are hacks to remove as much HTTP headers as possible
result.ResponseFilter = new NotModifiedContentTypeWriter();
// Removes the content-type header
base.Request.ResponseContentType = string.Empty;
return result;
}
class NotModifiedContentTypeWriter : ServiceStack.ServiceHost.IContentTypeWriter
{
ServiceStack.ServiceHost.ResponseSerializerDelegate ServiceStack.ServiceHost.IContentTypeWriter.GetResponseSerializer(string contentType)
{
return ResponseSerializerDelegate;
}
void ServiceStack.ServiceHost.IContentTypeWriter.SerializeToResponse(ServiceStack.ServiceHost.IRequestContext requestContext, object response, ServiceStack.ServiceHost.IHttpResponse httpRes)
{
}
void ServiceStack.ServiceHost.IContentTypeWriter.SerializeToStream(ServiceStack.ServiceHost.IRequestContext requestContext, object response, System.IO.Stream toStream)
{
}
string ServiceStack.ServiceHost.IContentTypeWriter.SerializeToString(ServiceStack.ServiceHost.IRequestContext requestContext, object response)
{
return string.Empty;
}
public void ResponseSerializerDelegate(ServiceStack.ServiceHost.IRequestContext requestContext, object dto, ServiceStack.ServiceHost.IHttpResponse httpRes)
{
}
}