{"action":"created","issue":{"url":"https://api.github.com/repos/pallets/flask/issues/1321","repository_url":"https://api.github.com/repos/pallets/flask","labels_url":"https://api.github.com/repos/pallets/flask/issues/1321/labels{/name}","comments_url":"https://api.github.com/repos/pallets/flask/issues/1321/comments","events_url":"https://api.github.com/repos/pallets/flask/issues/1321/events","html_url":"https://github.com/pallets/flask/issues/1321","id":54672145,"number":1321,"title":"Make it easier to serve 304 (Not Modified) using a database file.","user":{"login":"flying-sheep","id":291575,"avatar_url":"https://avatars.githubusercontent.com/u/291575?v=3","gravatar_id":"","url":"https://api.github.com/users/flying-sheep","html_url":"https://github.com/flying-sheep","followers_url":"https://api.github.com/users/flying-sheep/followers","following_url":"https://api.github.com/users/flying-sheep/following{/other_user}","gists_url":"https://api.github.com/users/flying-sheep/gists{/gist_id}","starred_url":"https://api.github.com/users/flying-sheep/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flying-sheep/subscriptions","organizations_url":"https://api.github.com/users/flying-sheep/orgs","repos_url":"https://api.github.com/users/flying-sheep/repos","events_url":"https://api.github.com/users/flying-sheep/events{/privacy}","received_events_url":"https://api.github.com/users/flying-sheep/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/pallets/flask/labels/enhancement","name":"enhancement","color":"c7def8"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2015-01-17T19:27:17Z","updated_at":"2016-06-04T07:01:33Z","closed_at":null,"body":"Currently, i have to do this if i want to simply reply 304.\r\n\r\ngiven an object `f` with the fields `mime`, `modified` and `data`:\r\n\r\n```python\r\nrv = send_file(BytesIO(f.data), mimetype=f.mime)\r\nrv.last_modified = f.modified.timestamp()\r\nreturn rv.make_conditional(request)\r\n```\r\n\r\nusing python 2, this would be worse, as it is most times:\r\n\r\n```python\r\nrv.last_modified = (f.modified - datetime(1970, 1, 1)).total_seconds()\r\n```\r\n\r\ni’d like to have a way to make use of a `datetime` object or POSIX timestamp in combination with the existing `conditional` argument to `send_file`. a way that one can use without having to discover `last_modified` and `make_conditional` both, e.g. (`last_modified` can be a `datetime` or timestamp):\r\n\r\n```python\r\nreturn send_file(BytesIO(f.data), mimetype=f.mime,\r\n                 conditional=True, last_modified=f.modified)\r\n```\r\n\r\nDocs\r\n----\r\nthe documentation to the `conditional` parameter would be extended to mention that `last_timestamp` has to be supplied if the first argument is a file handle instead of a name.\r\n\r\nImplementation\r\n--------------\r\nwe could create a helper function:\r\n\r\n```python\r\ndef to_timestamp(da_ti):\r\n    if PY2:\r\n        epoch = datetime(1970, 1, 1, tzinfo=da_ti.tzinfo)  # use tzinfo to ensure subtractability\r\n        return (da_ti - epoch).total_seconds()\r\n    else:  # we do require python 3 >= 3.3, right?\r\n        return da_ti.timestamp()\r\n```"},"comment":{"url":"https://api.github.com/repos/pallets/flask/issues/comments/223740840","html_url":"https://github.com/pallets/flask/issues/1321#issuecomment-223740840","issue_url":"https://api.github.com/repos/pallets/flask/issues/1321","id":223740840,"user":{"login":"davidism","id":1242887,"avatar_url":"https://avatars.githubusercontent.com/u/1242887?v=3","gravatar_id":"","url":"https://api.github.com/users/davidism","html_url":"https://github.com/davidism","followers_url":"https://api.github.com/users/davidism/followers","following_url":"https://api.github.com/users/davidism/following{/other_user}","gists_url":"https://api.github.com/users/davidism/gists{/gist_id}","starred_url":"https://api.github.com/users/davidism/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidism/subscriptions","organizations_url":"https://api.github.com/users/davidism/orgs","repos_url":"https://api.github.com/users/davidism/repos","events_url":"https://api.github.com/users/davidism/events{/privacy}","received_events_url":"https://api.github.com/users/davidism/received_events","type":"User","site_admin":false},"created_at":"2016-06-04T07:01:33Z","updated_at":"2016-06-04T07:01:33Z","body":"~~~python\r\nrv = send_file(BytesIO(b'hello'), mimetype='text/plain')\r\nrv.last_modified = datetime.utcnow()\r\nreturn rv.make_conditional(request)\r\n~~~\r\n\r\nThis works.  Are we ok with not having a `last_modified` argument for `send_file`?  Seems like it would be useful."}}
{"actor":{"display_login":"davidism"}}