From 6ab7cf694371b8309a243ddfbe87214c1d7c2016 Mon Sep 17 00:00:00 2001 From: Zbigniew Siciarz Date: Mon, 13 Jun 2011 12:09:27 +0200 Subject: [PATCH] Viewing and setting cookies. --- httpbin/core.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/httpbin/core.py b/httpbin/core.py index 063c0a6..6c1634d 100644 --- a/httpbin/core.py +++ b/httpbin/core.py @@ -178,5 +178,23 @@ def view_status_code(code): return status_code(code) +@app.route('/cookies') +@json_resource +def view_cookies(): + """Returns cookie data.""" + + return request.cookies + + +@app.route('/set-cookie//') +def set_cookie(name, value): + """Sets a cookie and redirects to cookie list.""" + + response = app.make_response(redirect('/cookies')) + response.set_cookie(key=name, value=value) + + return response + + if __name__ == '__main__': - app.run() \ No newline at end of file + app.run()