Skip to content

Instantly share code, notes, and snippets.

@jnewman
Created September 12, 2014 18:21
Show Gist options
  • Save jnewman/29da20259bd8e4fe91ee to your computer and use it in GitHub Desktop.
Save jnewman/29da20259bd8e4fe91ee to your computer and use it in GitHub Desktop.
Reproduce issue in Firebug network tab
from datetime import datetime
from flask import Flask, render_template, request, make_response
from argparse import ArgumentParser
app = Flask(__name__)
DEFAULT_HOST = 'example.com'
app.config['HOST'] = DEFAULT_HOST
@app.route('/cookies')
def cookies_setter():
resp = make_response(render_template('cookies.html'))
now = '{0}'.format(datetime.now())
host = app.config['HOST']
if not request.cookies.get('short'):
resp.headers.add(
'Set-Cookie', 'short=' + now + '; path=/; domain=.' + host + '; expires=Wed, 11-Mar-15 13:50:34 GMT'
)
if not request.cookies.get('long'):
resp.headers.add(
'Set-Cookie', 'long=' + now + '; path=/; domain=.' + host + '; expires=Wed, 11-Mar-2015 00:30:34 GMT;'
)
if not request.cookies.get('session'):
resp.headers.add('Set-Cookie', 'session=' + now + '; path=/; domain=.' + host + ';')
return resp
@app.route('/show-cookies')
def cookies_shower():
resp = make_response(render_template('cookies.html'))
return resp
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument('-p', '--port', default=9000, help='port to run on', type=int)
parser.add_argument('-H', '--host', default=DEFAULT_HOST, help='port to run on', type=str)
args = parser.parse_args()
app.config['HOST'] = args.host
app.run(port=args.port, debug=True)
<!DOCTYPE html>
<html>
<head></head>
<body>
<div id="log"></div>
<script>
(function() {
var cookies = document.cookie.split(';');
var span = document.createElement('span');
span.innerHTML = cookies.filter(function(cookie) {
return /(\s|^)+(long|short|session)=/.test(cookie);
}).join('<br />');
var log = document.getElementById('log');
log.appendChild(span);
})();
</script>
</body>
</html>
Flask==0.10.1
Jinja2==2.7.3
MarkupSafe==0.23
Werkzeug==0.9.6
argparse==1.2.1
itsdangerous==0.24
wsgiref==0.1.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment