This repository has been archived by the owner on Mar 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #353 from alphagov/feature/cache-control
HTTP validation is different to staleness
- Loading branch information
Showing
3 changed files
with
21 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
""" | ||
HTTP Validation decorators for flask apps | ||
See http://tools.ietf.org/html/rfc7234#section-4.3 | ||
""" | ||
import hashlib | ||
from flask import make_response, request | ||
from functools import wraps | ||
|
||
|
||
def etag(func): | ||
@wraps(func) | ||
def new_func(*args, **kwargs): | ||
resp = make_response(func(*args, **kwargs)) | ||
resp.set_etag(hashlib.sha1(resp.data).hexdigest()) | ||
resp.make_conditional(request) | ||
return resp | ||
|
||
return new_func |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters