I have registered a new content type in ServiceStack with:
appHost.ContentTypeFilters.Register("application/x-my-content-type",
SerializeToStream, DeserializeFromStream);
And everything works as expected, if the client sends the content type in the http stream.
Unfortunately, I have a client that is not in my control of HTTP Request Heads and does not send the content type.
How can I get ServiceStack to set the default content type for that route?
On every ServiceStack /metadata page lists the different ways a client can request a specific Content-Type:
E.g. The client can specify your custom ContentType with ?format=x-my-content-type, adding
.x-my-content-type
extension or by specifying the HTTP Header (in the HttpClient):Otherwise if your HttpClient doesn't send an Accept header you can specify the default content type in your AppHost with:
Note: All Configuration options in ServiceStack are set on
HostConfig
.The issue when calling web services from a web browser is that they typically ask for
Accept: text/html
which by contract ServiceStack obliges by returning back HTML if it is enabled.To ensure your Content-Type is always returned you may also want to disable the HTML feature with:
Otherwise if you want to override the Accept header you can force your service to always return your Content-Type by decorating your Response DTO inside a HttpResult, i.e:
Otherwise anywhere outside of your Service (e.g. Request/Response filter) you can set the Response ContentType anywhere that has access to a
IHttpRequest
with: