-
Notifications
You must be signed in to change notification settings - Fork 868
Add if-range header support #1751
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
Conversation
kazuho
left a comment
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.
Thank you for the PR. It looks very good to me.
I have left some minor comments in-line. Please let me know what you think.
| if ((range_header_index = h2o_find_header(&req->headers, H2O_TOKEN_RANGE, SIZE_MAX)) != -1) { | ||
| /* if range */ | ||
| if ((if_range_header_index = h2o_find_header(&req->headers, H2O_TOKEN_IF_RANGE, SIZE_MAX)) != -1) { | ||
| h2o_iovec_t *if_range = &req->headers.entries[if_range_header_index].value; |
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.
Could we extract the strong etag comparison logic as a dedicated function, so that we can have unit tests / call in from other parts of the code?
lib/handler/file.c
Outdated
| /* if range */ | ||
| if ((if_range_header_index = h2o_find_header(&req->headers, H2O_TOKEN_IF_RANGE, SIZE_MAX)) != -1) { | ||
| h2o_iovec_t *if_range = &req->headers.entries[if_range_header_index].value; | ||
| if (if_range->base[0] == 'W' && if_range->base[1] == '/' && if_range->base[2] == '"') /* weak etag */ |
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.
I believe that we need to check the length before evaluating the elements, assuming that if_range is just a memory chunk rather than a NUL-terminated string.
|
So strong etag comparison logic has been extracted. Though I'm not sure where to put so currently it is put in |
kazuho
left a comment
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.
Thank you for the changes.
Aside from my comments in-line, the code looks ready for merge. I appreciate having unit tests for the ETag comparison function. Thank you very much.
lib/common/filecache.c
Outdated
|
|
||
| /* first check if tag1 a valid strong etag, then just strictly compare tag1 with tag2 */ | ||
| if (tag1_len > strlen("W/\"\"") && memcmp(tag1, "W/\"", 3) == 0) /* at least a weak etag */ | ||
| return 0; |
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.
Do we need this check, i.e. if the string begins with W/, considering the fact that we only care about strings starting with " (as been tested below)?
include/h2o/filecache.h
Outdated
| void h2o_filecache_close_file(h2o_filecache_ref_t *ref); | ||
| struct tm *h2o_filecache_get_last_modified(h2o_filecache_ref_t *ref, char *outbuf); | ||
| size_t h2o_filecache_get_etag(h2o_filecache_ref_t *ref, char *outbuf); | ||
| int h2o_filecache_compare_etag_strong(char *tag1, size_t tag1_len, char *tag2, size_t tag2_len); |
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.
Please use const char * for the strings.
|
Code has been updated according to last comments. |
|
Thank you for the changes. Merged to master. |
This PR adds
if-rangecondition header support forlib/handler/file.c.