Skip to content

Instantly share code, notes, and snippets.

@superkarn
Created October 22, 2012 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save superkarn/3933392 to your computer and use it in GitHub Desktop.
Save superkarn/3933392 to your computer and use it in GitHub Desktop.
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