Skip to content

Instantly share code, notes, and snippets.

@igorkulman
Last active August 29, 2015 14:19
Show Gist options
  • Save igorkulman/4e6d24d0fedfe8361c6b to your computer and use it in GitHub Desktop.
Save igorkulman/4e6d24d0fedfe8361c6b to your computer and use it in GitHub Desktop.
/// <summary>
/// Gets response with ETag. Returns empty body if ETag matches (no data changes)
/// </summary>
/// <param name="data">Data to match with ETag</param>
/// <param name="model">Model to return</param>
/// <returns>Response</returns>
protected Response GetResponseWithEtag(object data, object model)
{
string etag = Utils.ComputeHash(data);
if (CacheHelpers.ReturnNotModified(etag, null, this.Context))
{
return HttpStatusCode.NotModified;
}
return Response.AsJson(model).WithHeader("ETag", etag);
}
Get["/startlist/{id}"] = parameters =>
{
var startList = _competitionService.GetStartList((int)parameters.id);
var model = new StartListModel() { StartList = startList };
return GetResponseWithEtag(startList, model);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment