-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
fileresponse content-range header #2847
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2847 +/- ##
==========================================
+ Coverage 97.97% 97.97% +<.01%
==========================================
Files 39 39
Lines 7444 7461 +17
Branches 1307 1308 +1
==========================================
+ Hits 7293 7310 +17
Misses 48 48
Partials 103 103
Continue to review full report at Codecov.
|
According to codecov, in web_fileresponse.py: |
Sorry about the commits |
@spcharc thank you for contribution. |
Thank you! |
Now Content-Range is also provided when HTTP 416 is returned. No test case change for this commit (577c81a). |
…f-unmodified-since
…f-unmodified-since
…into fileresp-header
No more changes of this PR beyond this point. ETag not supported yet (seems unnecessary) |
It's up to you. I'm ok with |
I'm ok with not supporting multi-range requests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just small improvements needed.
aiohttp/web_fileresponse.py
Outdated
@@ -166,7 +167,12 @@ def __init__(self, path, chunk_size=256*1024, *args, **kwargs): | |||
modsince = request.if_modified_since | |||
if modsince is not None and st.st_mtime <= modsince.timestamp(): | |||
self.set_status(HTTPNotModified.status_code) | |||
self._length_check = False | |||
# self._length_check = False <- why this line is needed? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://github.com/aio-libs/aiohttp/blob/master/aiohttp/web_response.py#L340
Looks like is is important for chunked encoding, I don't recall details honestly.
Maybe @fafhrd91 can shed a light?
Returns :class:`datetime.datetime` or ``None`` if | ||
*If-Unmodified-Since* header is absent or is not a valid | ||
HTTP date. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here should be ..versionadded:: 3.1
tag.
Returns :class:`datetime.datetime` or ``None`` if | ||
*If-Range* header is absent or is not a valid | ||
HTTP date. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. versionadded::
Thanks for review. |
I suddenly realized that content-length could be set by a user! |
…p_date method for BaseRequest
…into fileresp-header
@spcharc thank you, very high quality work! |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs. |
Feel free to close this request if it is not properly written. I'm still learning how to use github
What do these changes do?
for instance,
file.size() == 200
but client gives this header
request.header['Range'] == 'bytes=99999-'
for instance,
file.size() == 200
but client gives this header
request.header['Range'] == 'bytes=-99999'
It seems that reify class uses
function.__name__
as the key to store results ...Their code is just the same with if_modified_since actually
Maybe I should create a _private_func (of course not a reify decorated one) and use that. Copy and paste the same piece of code is not interesting.
Besides, some existing test functions get updated. They check Content-Range header now.
Are there changes in behavior for the user?
New headers returned
Out-of-range start-range requests result in HTTP 416
these are behavior changes, nothing more
Related issue number
#2844 However it won't be fully solved, as multipart/byteranges is still not supported.
multipart/byteranges support involves:
It should be able to handle multiple ranges and return a tuple of slices
This will break existing code.
Checklist
I think this question is for you. Everbody considers him/her-self good code writers
I added a few comments though. I think the comments are well written
Old test cases modified + new ones
Request.if_range and Request.if_unmodified_since are now reflected in Server->reference page
CONTRIBUTORS.txt
I didn't know about this until everything is ready for a pull request. Went back and updated it
CHANGES
folder<issue_id>.<type>
for example (588.bugfix)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.OK. I went back and added 2844.feature
file content:"Provide Content-Range header for Range requests"
actually it's an improvement for an existing feature, not a new one
Question
In web_fileresponse.py, line 170
self._length_check = False
What is this for? I failed to figure out what it is.
_length_check is in StreamResponse(web_response.py). I commented out this line and everything still worked. That's strange
line 170 is returning an http error.
Returning other http errors in FileResponse do not involve setting _length_check to False.
Edit: Question solved. Actually I had made a
grep -r _length_check
search and found it in web_response.py before I made this PR. But I failed to understand that users could also set the Content-Length header at that time.