Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@zlm2012
Copy link
Contributor

@zlm2012 zlm2012 commented May 1, 2018

This PR adds if-range condition header support for lib/handler/file.c.

Copy link
Member

@kazuho kazuho left a 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;
Copy link
Member

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?

/* 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 */
Copy link
Member

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.

@zlm2012
Copy link
Contributor Author

zlm2012 commented May 22, 2018

So strong etag comparison logic has been extracted. Though I'm not sure where to put so currently it is put in common/filecache.c.

Copy link
Member

@kazuho kazuho left a 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.


/* 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;
Copy link
Member

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)?

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);
Copy link
Member

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.

@zlm2012
Copy link
Contributor Author

zlm2012 commented Jun 3, 2018

Code has been updated according to last comments.

@kazuho kazuho merged commit 9a7d6bc into h2o:master Jun 3, 2018
@kazuho
Copy link
Member

kazuho commented Jun 3, 2018

Thank you for the changes. Merged to master.

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

Successfully merging this pull request may close these issues.

2 participants