Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This attribute forces a particular request to be secure (over SSL).
public class SecureRequestFilterAttribute : Attribute, IHasRequestFilter
{
public IHasRequestFilter Copy()
{
return this;
}
public int Priority
{
// https://github.com/ServiceStack/ServiceStack/issues/119
// By setting priority to -100, this filter will be applied first.
get { return -100; }
}
public void RequestFilter(IHttpRequest req, IHttpResponse res, object requestDto)
{
// https://groups.google.com/d/msg/servicestack/7JnQ8eLf36M/JFx2g7xEeEkJ
if (!req.IsSecureConnection)
{
res.StatusCode = (int)HttpStatusCode.Forbidden;
res.Close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment