Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loss of the cookie state when using max-age=0. #5743

Open
luckydenis opened this issue Feb 5, 2021 · 1 comment
Open

Loss of the cookie state when using max-age=0. #5743

luckydenis opened this issue Feb 5, 2021 · 1 comment

Comments

@luckydenis
Copy link
Contributor

Summary.
Loss of the cookie state when receiving a response from the server containing the lifetime in the format max-age=0.

Expected Result

import requests
r = requests.get('http://127.0.0.1:5000/expire')
>>> r.headers
{'Set-Cookie': 'test=test; Path=/; Max-Age=0', 'Content-Type': 'text/html; charset=utf-8', 'Content-Length': '10', 'Server': 'Werkzeug/1.0.1 Python/3.8.7', 'Date': 'Fri, 05 Feb 2021 09:26:48 GMT'}
>>> r.cookies
<RequestsCookieJar[Cookie(version=0, name='test', value='test', port=None, port_specified=False, domain='127.0.0.1', domain_specified=False, domain_initial_dot=False, path='/', path_specified=True, secure=False, expires=1612520808, discard=False, comment=None, comment_url=None, rest={}, rfc2109=False)]>

Actual Result

>>> import requests
>>> r = requests.get('http://127.0.0.1:5000/expire')
>>> r.headers
{'Set-Cookie': 'test=test; Path=/; Max-Age=0', 'Content-Type': 'text/html; charset=utf-8', 'Content-Length': '14', 'Server': 'Werkzeug/1.0.1 Python/3.8.7', 'Date': 'Fri, 05 Feb 2021 09:16:43 GMT'}
>>> r.cookies
<RequestsCookieJar[]>

Reproduction Steps

app.py

from flask import Flask, make_response


app = Flask(__name__)


@app.route('/expire')
def expire():
    return "Expired cookie", {'Set-Cookie': 'test=test; Path=/; Max-Age=0'}

Start app: FLASK_APP=app.py flask run -p 5000

test.py

import requests


r = requests.get('http://127.0.0.1:5000/expire')
print('headers:', r.headers)
print()
print('cookies:', r.cookies)

output

headers: {'Set-Cookie': 'test=test; Path=/; Max-Age=0', 'Content-Type': 'text/html; charset=utf-8', 'Content-Length': '14', 'Server': 'Werkzeug/1.0.1 Python/3.8.7', 'Date': 'Fri, 05 Feb 2021 09:40:32 GMT'}

cookies: <RequestsCookieJar[]>

System Information

$ python -m requests.help
{
  "chardet": {
    "version": "4.0.0"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "2.10"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.8.7"
  },
  "platform": {
    "release": "5.8.0-41-generic",
    "system": "Linux"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.25.1"
  },
  "system_ssl": {
    "version": "1010106f"
  },
  "urllib3": {
    "version": "1.26.3"
  },
  "using_pyopenssl": false
}

This command is only available on Requests v2.16.4 and greater. Otherwise,
please provide some basic information about your system (Python version,
operating system, &c).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant