Examine Request Headers with ServiceStack

What is the best way to check request headers for a service endpoint?

ContactService : Service 

After reading this https://github.com/ServiceStack/ServiceStack/wiki/Access-HTTP-specific-features-in-services , I wonder how to get to the interface.

Thanks Steven

+6
source share
1 answer

Inside the ServiceStack Service, you can access IHttpRequest and IHttpResponse with:

 public class ContactService : Service { public object Get(Contact request) { var headerValue = base.Request.Headers[headerKey]; //or the same thing via a more abstract (and easier to Mock): var headerValue = base.RequestContext.GetHeader(headerKey); } } 

IHttpRequest is a wrapper over the underlying ASP.NET HttpRequest or HttpListenerRequest (depending on whether you are hosted on ASP.NET or a self-hosted HttpListener). Therefore, if you are working in ASP.NET, you can get the basic ASP.NET HttpRequest with

 var aspnetRequest = (HttpRequest)base.Request.OriginalRequest; var headerValue = aspnetRequest.Headers[headerKey]; 
+7
source

All Articles