diff --git a/AUTHORS b/AUTHORS index 44f0c9e..e3c8c39 100644 --- a/AUTHORS +++ b/AUTHORS @@ -18,3 +18,4 @@ Patches and Suggestions - Radomir Stevanovic (http://github.com/randomir) - Steven Honson - Cory Benfield (Lukasa) +- Matt Robenolt (https://github.com/mattrobenolt) diff --git a/README.md b/README.md index c1032c8..a0d13e2 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Freely hosted in [HTTP](http://httpbin.org) & - [`/html`](http://httpbin.org/html) Renders an HTML Page. - [`/robots.txt`](http://httpbin.org/robots.txt) Returns some robots.txt rules. - [`/deny`](http://httpbin.org/deny) Denied by robots.txt file. -- [`/cache`](http://httpbin.org/cache) Returns 200 unless an If-Modified-Since header is provided, when it returns a 304. +- [`/cache`](http://httpbin.org/cache) Returns 200 unless an If-Modified-Since or If-None-Match header is provided, when it returns a 304. ## DESCRIPTION diff --git a/httpbin/core.py b/httpbin/core.py index ed2a065..d232180 100644 --- a/httpbin/core.py +++ b/httpbin/core.py @@ -11,10 +11,12 @@ import base64 import json import os import time +import uuid from flask import Flask, Response, request, render_template, redirect, jsonify, make_response from raven.contrib.flask import Sentry from werkzeug.datastructures import WWWAuthenticate +from werkzeug.http import http_date from . import filters from .helpers import get_headers, status_code, get_dict, check_basic_auth, check_digest_auth, H, ROBOT_TXT, ANGRY_ASCII @@ -332,11 +334,14 @@ def decode_base64(value): @app.route('/cache', methods=('GET',)) def cache(): - """Returns a 304 if an If-Modified-Since header is present. Returns the same as a GET otherwise.""" - if_modified = request.headers.get('If-Modified-Since') + """Returns a 304 if an If-Modified-Since header or If-None-Match is present. Returns the same as a GET otherwise.""" + is_conditional = request.headers.get('If-Modified-Since') or request.headers.get('If-None-Match') - if if_modified is None: - return view_get() + if is_conditional is None: + response = view_get() + response.headers['Last-Modified'] = http_date() + response.headers['ETag'] = uuid.uuid4().hex + return response else: return status_code(304)