diff --git a/AUTHORS b/AUTHORS index 2ca4276f..0c4f6fc6 100644 --- a/AUTHORS +++ b/AUTHORS @@ -15,4 +15,5 @@ Patches and Suggestions - Lispython - Kyle Conroy - Flavio Percoco -- Radomir Stevanovic (http://github.com/randomir) \ No newline at end of file +- Radomir Stevanovic (http://github.com/randomir) +- Steven Honson diff --git a/README.md b/README.md index 37251c8c..0a1ab64b 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/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. diff --git a/httpbin/core.py b/httpbin/core.py index 9bd95214..c13f3392 100644 --- a/httpbin/core.py +++ b/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//') 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 5b3d2a45..182da11f 100644 --- a/httpbin/templates/httpbin.1.html +++ b/httpbin/templates/httpbin.1.html @@ -21,6 +21,7 @@

ENDPOINTS

  • /relative-redirect/:n 302 Relative redirects n times.
  • /cookies Returns cookie data.
  • /cookies/set/:name/:value Sets a simple cookie.
  • +
  • /cookies/set?name=value Sets 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.