From 802b1ea739f20c979e8cae405e1b28a099ceaf50 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Wed, 10 Jul 2013 18:00:54 -0400 Subject: [PATCH] cache control /cc @mattrobenolt --- README.md | 2 +- httpbin/core.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9686483..9ea1134 100644 --- a/README.md +++ b/README.md @@ -32,11 +32,11 @@ Freely hosted in [HTTP](http://httpbin.org) & - [`/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 or If-None-Match header is provided, when it returns a 304. +- [`/cache/:n`](http://httpbin.org/cache/60) Sets a Cache-Control header for *n* seconds. - [`/bytes/:n`](http://httpbin.org/bytes/1024) Generates *n* random bytes of binary data, accepts optional *seed* integer parameter. - [`/stream-bytes/:n`](http://httpbin.org/stream-bytes/1024) Streams *n* random bytes of binary data, accepts optional *seed* and *chunk_size* integer parameters. - [`/links/:n`](http://httpbin.org/links/10) Returns page containing *n* HTML links. - ## DESCRIPTION Testing an HTTP Library can become difficult sometimes. PostBin.org is fantastic diff --git a/httpbin/core.py b/httpbin/core.py index dca9af2..b503160 100644 --- a/httpbin/core.py +++ b/httpbin/core.py @@ -368,6 +368,14 @@ def cache(): return status_code(304) +@app.route('/cache/') +def cache_control(value): + """Sets a Cache-Control header.""" + response = view_get() + response.headers['Cache-Control'] = 'public, max-age={0}'.format(value) + return response + + @app.route('/bytes/') def random_bytes(n): """Returns n random bytes generated with given seed."""