Skip to content

Commit

Permalink
Support for setting multiple cookies in a single request.
Browse files Browse the repository at this point in the history
  • Loading branch information
snh committed Aug 20, 2012
1 parent 46e00b7 commit b1196a2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion AUTHORS
Expand Up @@ -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
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions httpbin/core.py
Expand Up @@ -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."""
Expand Down
1 change: 1 addition & 0 deletions httpbin/templates/httpbin.1.html
Expand Up @@ -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>
Expand Down

0 comments on commit b1196a2

Please sign in to comment.