From 6287af8186fa44f9d1ca581a6b37bdff701f3287 Mon Sep 17 00:00:00 2001 From: Steven Honson Date: Mon, 20 Aug 2012 23:35:03 +1000 Subject: [PATCH 1/2] New delete cookie endpoint. --- README.md | 1 + httpbin/core.py | 12 ++++++++++++ httpbin/templates/httpbin.1.html | 1 + 3 files changed, 14 insertions(+) diff --git a/README.md b/README.md index df6687f..238118e 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ Freely hosted in [HTTP](http://httpbin.org) & - [`/relative-redirect/:n`](http://httpbin.org/relative-redirect/6) 302 Relative redirects *n* times. - [`/cookies`](http://httpbin.org/cookies) Returns cookie data. - [`/cookies/set?name=value`](http://httpbin.org/cookies/set?k1=v1&k2=v2) Sets one or more simple cookies. +- [`/cookies/delete?name`](http://httpbin.org/cookies/delete?k1) Deletes one or more simple cookies. - [`/basic-auth/:user/:passwd`](http://httpbin.org/basic-auth/user/passwd) Challenges HTTPBasic Auth. - [`/hidden-basic-auth/:user/:passwd`](http://httpbin.org/hidden-basic-auth/user/passwd) 404'd BasicAuth. - [`/digest-auth/:qop/:user/:passwd`](http://httpbin.org/digest-auth/auth/user/passwd) Challenges HTTP Digest Auth. diff --git a/httpbin/core.py b/httpbin/core.py index c13f339..d3ec9a6 100644 --- a/httpbin/core.py +++ b/httpbin/core.py @@ -271,6 +271,18 @@ def set_cookies(): return r +@app.route('/cookies/delete') +def delete_cookies(): + """Deletes cookie(s) as provided by the query string and redirects to cookie list.""" + + cookies = dict(request.args.items()) + r = app.make_response(redirect('/cookies')) + for key, value in cookies.items(): + r.delete_cookie(key=key) + + return r + + @app.route('/basic-auth//') def basic_auth(user='user', passwd='passwd'): """Prompts the user for authorization using HTTP Basic Auth.""" diff --git a/httpbin/templates/httpbin.1.html b/httpbin/templates/httpbin.1.html index eae602d..5241248 100644 --- a/httpbin/templates/httpbin.1.html +++ b/httpbin/templates/httpbin.1.html @@ -21,6 +21,7 @@
  • /relative-redirect/:n 302 Relative redirects n times.
  • /cookies Returns cookie data.
  • /cookies/set?name=value Sets one or more simple cookies.
  • +
  • /cookies/delete?name Deletes one or more simple cookies.
  • /basic-auth/:user/:passwd Challenges HTTPBasic Auth.
  • /hidden-basic-auth/:user/:passwd 404'd BasicAuth.
  • /digest-auth/:qop/:user/:passwd Challenges HTTP Digest Auth.
  • From 08f8f0b516d44818977662da501d600d4f0c528b Mon Sep 17 00:00:00 2001 From: Steven Honson Date: Mon, 20 Aug 2012 23:40:45 +1000 Subject: [PATCH 2/2] Updated example linked to include two deletions. --- README.md | 2 +- httpbin/templates/httpbin.1.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 238118e..bb0ecb2 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Freely hosted in [HTTP](http://httpbin.org) & - [`/relative-redirect/:n`](http://httpbin.org/relative-redirect/6) 302 Relative redirects *n* times. - [`/cookies`](http://httpbin.org/cookies) Returns cookie data. - [`/cookies/set?name=value`](http://httpbin.org/cookies/set?k1=v1&k2=v2) Sets one or more simple cookies. -- [`/cookies/delete?name`](http://httpbin.org/cookies/delete?k1) Deletes one or more simple cookies. +- [`/cookies/delete?name`](http://httpbin.org/cookies/delete?k1&k2) Deletes one or more simple cookies. - [`/basic-auth/:user/:passwd`](http://httpbin.org/basic-auth/user/passwd) Challenges HTTPBasic Auth. - [`/hidden-basic-auth/:user/:passwd`](http://httpbin.org/hidden-basic-auth/user/passwd) 404'd BasicAuth. - [`/digest-auth/:qop/:user/:passwd`](http://httpbin.org/digest-auth/auth/user/passwd) Challenges HTTP Digest Auth. diff --git a/httpbin/templates/httpbin.1.html b/httpbin/templates/httpbin.1.html index 5241248..d86cc19 100644 --- a/httpbin/templates/httpbin.1.html +++ b/httpbin/templates/httpbin.1.html @@ -21,7 +21,7 @@
  • /relative-redirect/:n 302 Relative redirects n times.
  • /cookies Returns cookie data.
  • /cookies/set?name=value Sets one or more simple cookies.
  • -
  • /cookies/delete?name Deletes one or more simple cookies.
  • +
  • /cookies/delete?name Deletes one or more simple cookies.
  • /basic-auth/:user/:passwd Challenges HTTPBasic Auth.
  • /hidden-basic-auth/:user/:passwd 404'd BasicAuth.
  • /digest-auth/:qop/:user/:passwd Challenges HTTP Digest Auth.