Skip to content
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_client: http_client_req() returns incorrect number of bytes sent #43829

Closed
ewalt1 opened this issue Mar 15, 2022 · 1 comment · Fixed by #43916
Closed

http_client: http_client_req() returns incorrect number of bytes sent #43829

ewalt1 opened this issue Mar 15, 2022 · 1 comment · Fixed by #43916
Assignees
Labels
area: Networking bug The issue is a bug, or the PR is fixing a bug

Comments

@ewalt1
Copy link

ewalt1 commented Mar 15, 2022

The http_client_req() function is supposed to return the number of bytes sent to the server:
https://github.com/zephyrproject-rtos/zephyr/blob/main/include/net/http_client.h#L327

However, there is a bug in the implementation such that it generally returns something much larger. Each line of the headers is sent via one call to http_send_data(), the return value of which is added to the total_sent summation variable.
https://github.com/zephyrproject-rtos/zephyr/blob/main/subsys/net/lib/http/http_client.c#L529

However, http_send_data() doesn't typically return the number of bytes that were added in that particular invocation. Instead it copies the values into a local 192 byte buffer and returns the current position within that buffer.

For example, if I wanted to send:

        PATCH /v1/123456789abcd HTTP/1.1
        Host: xxxxxxxxxxxxxxxxxx.uc.r.appspot.com
        Content-Length: 34

Then the http_client sends 33+43+22==98 bytes of headers plus my 34 bytes of payload for a total of 132 bytes.

However the calls to http_send_data() will return 33, (33 + 43), and (33 + 43 + 22) respectively. This leads to total_sent being set to 207 by the time the headers have been sent, which causes an incorrect return value of 207+34==241 from http_client_req().

@ewalt1 ewalt1 added the bug The issue is a bug, or the PR is fixing a bug label Mar 15, 2022
@rlubos rlubos self-assigned this Mar 17, 2022
@rlubos
Copy link
Contributor

rlubos commented Mar 17, 2022

@ewalt1 Please check #43916 where I proposed a fix for the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Networking bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants