Permalink
Browse files

Support for setting multiple cookies in a single request.

  • Loading branch information...
1 parent 46e00b7 commit b1196a239b862c3d7ce7809dbd84f667cfc4c014 @snh snh committed Aug 20, 2012
Showing with 16 additions and 1 deletion.
  1. +2 −1 AUTHORS
  2. +1 −0 README.md
  3. +12 −0 httpbin/core.py
  4. +1 −0 httpbin/templates/httpbin.1.html
View
3 AUTHORS
@@ -15,4 +15,5 @@ Patches and Suggestions
- Lispython
- Kyle Conroy
- Flavio Percoco
-- Radomir Stevanovic (http://github.com/randomir)
+- Radomir Stevanovic (http://github.com/randomir)
+- Steven Honson
View
1 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/key/value) Sets a simple cookie.
+- [`/cookies/set?name=value`](http://httpbin.org/cookies/set?k1=v1&k2=v2) Sets 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.
View
12 httpbin/core.py
@@ -259,6 +259,18 @@ def set_cookie(name, value):
return r
+@app.route('/cookies/set')
+def set_cookies():
+ """Sets 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.set_cookie(key=key, value=value)
+
+ return r
+
+
@app.route('/basic-auth/<user>/<passwd>')
def basic_auth(user='user', passwd='passwd'):
"""Prompts the user for authorization using HTTP Basic Auth."""
View
1 httpbin/templates/httpbin.1.html
@@ -21,6 +21,7 @@ <h2 id="ENDPOINTS">ENDPOINTS</h2>
<li><a href="/relative-redirect/6"><code>/relative-redirect/:n</code></a> 302 Relative redirects <em>n</em> times.</li>
<li><a href="/cookies" data-bare-link="true"><code>/cookies</code></a> Returns cookie data.</li>
<li><a href="/cookies/set/key/value"><code>/cookies/set/:name/:value</code></a> Sets a simple cookie.</li>
+<li><a href="/cookies/set?k1=v1&amp;k2=v2"><code>/cookies/set?name=value</code></a> Sets one or more simple cookies.</li>
<li><a href="/basic-auth/user/passwd"><code>/basic-auth/:user/:passwd</code></a> Challenges HTTPBasic Auth.</li>
<li><a href="/hidden-basic-auth/user/passwd"><code>/hidden-basic-auth/:user/:passwd</code></a> 404'd BasicAuth.</li>
<li><a href="/digest-auth/auth/user/passwd"><code>/digest-auth/:qop/:user/:passwd</code></a> Challenges HTTP Digest Auth.</li>

0 comments on commit b1196a2

Please sign in to comment.