Используя ServiceStack, я просто хочу вернуть 304 Not Modified как таковой:
HTTP/1.1 304 Not Modified
Но ServiceStack добавляет много других нежелательных (, возвращающих HttpResult с заголовками кода 304 )как таковыми :
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
. Как я могу предотвратить вывод других заголовков? Я пробовал различные подходы с HttpResult , регистрируя фиктивный фильтр типа контента, но, как следует из его названия, контролирует только контент, а не заголовки или другие перечисленные здесь . Я также пытался реализовать свой собственный производный IHttpResult с помощью IStreamWriter и IHasOptions с теми же результатами. :ServiceStack добавляет нежелательные заголовки.
Спасибо
Обновление
Удалось удалить content-type
с помощью следующего, но некоторые заголовки все еще присутствуют, то есть content-length
, server
и 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)
{
}
}