-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Http Content Range #83528
Http Content Range #83528
Conversation
Hello @td-pradecki, and thank you very much for your first pull request to the Zephyr project! |
f6f1de8
to
176c18e
Compare
subsys/net/lib/http/http_client.c
Outdated
@@ -218,11 +218,16 @@ static int on_header_field(struct http_parser *parser, const char *at, | |||
struct http_request, | |||
internal.parser); | |||
const char *content_len = "Content-Length"; | |||
uint16_t len; | |||
const char *content_range = "Content-Range"; |
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 think we could change this to
const char content_range[]="Content-Range";
This way we avoid allocating a pointer and can use sizeof instead of strlen
Same change could be done for content-lenght.
Perhaps it could be even static.
FYI as an alternative approach it should be possible to handle the The approach in this PR also works, but hard-coding the response headers to be processed in the HTTP parser state machine might not be the most scalable approach if we want to handle more headers in future. E.g. a quick example of what I mean by modifying the HTTP client sample app:
|
d1bea07
to
e7cbdd6
Compare
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 some nits.
subsys/net/lib/http/http_parser.c
Outdated
case h_content_range_start: | ||
if (parser->content_range_present) { | ||
SET_ERRNO | ||
(HPE_UNEXPECTED_CONTENT_RANGE); |
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.
This line break seems unnecessary?
subsys/net/lib/http/http_client.c
Outdated
uint16_t content_len_len = sizeof(content_len)-1; | ||
uint16_t content_range_len = sizeof(content_range)-1; |
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.
Weird that checkpatch doesn't complain about this:
uint16_t content_len_len = sizeof(content_len)-1; | |
uint16_t content_range_len = sizeof(content_range)-1; | |
uint16_t content_len_len = sizeof(content_len) - 1; | |
uint16_t content_range_len = sizeof(content_range) - 1; |
Content-Range hasn't been supported in zephyr. This change adds Content-Range header parsing to http_parser module. Range start, range end, and total size are supported. All units are currently interpreted as bytes. This is much needed change, because many applications responsible for http data download are based on Content-Range approach. Signed-off-by: Piotr Radecki <[email protected]>
Three tests has been added for Content-Range functionality in http parser: - test_content_range_supplied: Checks if parser handles range correctly. - test_content_range_asterisk_total: Checks if parser interprets astersk as no total size supplied. - test_double_content_range_error: Checks if parser rejects header with repeated Content-Range field. Signed-off-by: Piotr Radecki <[email protected]>
e7cbdd6
to
54ce673
Compare
include/zephyr/net/http/parser.h
Outdated
@@ -160,6 +167,8 @@ struct http_parser { | |||
uint64_t content_length; /* # bytes in body (0 if no Content-Length | |||
* header) | |||
*/ | |||
uint8_t content_range_present; |
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 think this could be a bool
to make it clear the meaning of the field.
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 provided the remaining comment is addressed.
Content-Range functionality added in recent commits has been propagated to http_client module. If "Content-Range" string is detected on header field, Content-Range are returned via http_response structure. Signed-off-by: Piotr Radecki <[email protected]>
54ce673
to
cc547c0
Compare
Hi @td-pradecki! To celebrate this milestone and showcase your contribution, we'd love to award you the Zephyr Technical Contributor badge. If you're interested, please claim your badge by filling out this form: Claim Your Zephyr Badge. Thank you for your valuable input, and we look forward to seeing more of your contributions in the future! 🪁 |
Content-Range parsing has been added to the http subsystem.
PR consist of changes in:
http_parser: Added parsing Content-Range header. Parsing is done by writing
the output to the output structure called "http_content_range".
Structure contains fields: start, end, total. Unit automatically translates to bytes.
http_client: If header field matches Content-Range scheme, fields are returned via
http_content_range struct. cr_present flag indicates that Content-Range is present.
Changes are much needed because currently Zephyr doesn't support Content-Range header, which
is extensively used approach in http-based download apps.