Hi, Is there a way to check if the request originated from a browser or through code (api call)? I know there are request headers, but those can be set through code as well.
The characteristics of a browser request is they have a browser UserAgent and Accept
text/html
. Unless you have a good reason for differentiating between a browser request and any other API request that asks for a HTML response you should just be checking whether IRequest.ResponseContentType
returns HTML, i.e:
var returnHtml = Request.ResponseContentType.MatchesContentType(MimeTypes.Html);
Note: nothing in ServiceStack modifies the IRequest.Headers
which holds the HTTP Request Headers sent with the request, if they’re changed it’s something in your AppHost that’s doing it.