Opened 4 years ago
Closed 4 years ago
#31982 closed Cleanup/optimization (fixed)
Convert max_age to an int in set_cookie()
Reported by: | Matt Johnson | Owned by: | Hasan Ramezani |
---|---|---|---|
Component: | HTTP handling | Version: | 3.1 |
Severity: | Normal | Keywords: | |
Cc: | Florian Apolloner, Adam Johnson | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
The max-age attribute of cookie is supposed to be an integer
https://tools.ietf.org/html/rfc6265#page-20
I think it would be helpful to convert the max_age parameter of set_cookie() to an integer for the user. The benefit is simply that there are some cookie parsers that don't handle decimals gracefully. It's pretty easy to pass in a float without understanding the consequences. I spent a good chunk of time today trying to track down the problem.
Things to consider:
- Do we only convert floats where the decimal part is 0? Or do we round or truncate?
- If we can't successfully convert to an int, do we throw an exception, or just pass in the original value?
Change History (6)
comment:1 by , 4 years ago
Cc: | added |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Cleanup/optimization |
comment:3 by , 4 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:5 by , 4 years ago
Needs tests: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
Note:
See TracTickets
for help on using tickets.
Agreed, we should also mention this in docs, e.g.:
Replying to Matt Johnson:
I would simply call
int(max_age)
without catching exceptions.