Usando ServiceStack, sólo quiero volver 304 Not Modified como tal:Prevenir cabeceras no deseados cuando regresan 304 sin modificar con ServiceStack
HTTP/1.1 304 Not Modified
Pero ServiceStack añade muchas otras no deseado (volviendo HttpResult con 304 códigos) encabezados como tal:
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
¿Cómo puedo evitar que salgan los otros encabezados? He intentado varios enfoques con HttpResult, registrando un filtro de tipo de contenido ficticio, pero como su nombre implica solo controla el contenido, no los encabezados, u otros listados here. También intenté implementar mi propio derivado IHttpResult con IStreamWriter y IHasOptions con los mismos resultados: ServiceStack agrega encabezados no deseados.
Gracias
Actualizar
fue capaz de eliminar content-type
mediante el uso de lo siguiente, pero algunas cabeceras todavía están presentes es decir content-length
, server
, y 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)
{
}
}
Gracias por la respuesta, pero esto solo elimina los CORS, no los demás. Todavía tengo HTTP/1.1 304 No modificado Content-Length: 0 Content-Type: application/json Caduca: Jue, 16 de agosto de 2012 16:20:25 GMT Servidor: Microsoft-HTTPAPI/2.0 Fecha: Jue, 16 de agosto de 2012 16:20:24 GMT –
Los encabezados emitidos que no están en 'GlobalResponseHeaders' o que se agregan a usted por servicio con' HttpResult' no son de ServiceStack. IIS/ASP.NET puede elegir agregar sus propios encabezados. – mythz
No usa IIS/ASP.Net, solo prueba de aplicación de consola. Parece añadido desde el serializador JSON y otros. ¿Cómo puedo controlar esto? –