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 assumes request payload is non-binary #24431

Closed
arvinf opened this issue Apr 17, 2020 · 0 comments · Fixed by #24432
Closed

http_client assumes request payload is non-binary #24431

arvinf opened this issue Apr 17, 2020 · 0 comments · Fixed by #24432
Labels
area: Networking bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug

Comments

@arvinf
Copy link
Contributor

arvinf commented Apr 17, 2020

http_client.c uses strlen (in http_send_data) to calculate request payload size, instead of using payload_len that is provided by the user. This is incorrect and results in writing fewer bytes than is expected by the server when payload is binary.

An additional issue is that when payload_cb is used by the user to provide data via callback, no Content-Length is sent by http_client event if payload_len is provided. By the time payload_cb is invoked to provide the data the request headers have already been sent.

@arvinf arvinf added the bug The issue is a bug, or the PR is fixing a bug label Apr 17, 2020
@jukkar jukkar added area: Networking priority: medium Medium impact/importance bug labels Apr 17, 2020
jukkar pushed a commit that referenced this issue Apr 20, 2020
Bug fix and improved `payload` handling in `http_client_req`.

Changes to `http_client_req` behaviour:

If the user provides `payload_len` it is used to generate the
`Content-Length` header. This is done even if `payload_cb` is used to
provide the actual data. If no `payload_len` is specified then no
`Content-Length` is generated.

If `payload_cb` is provided it is called to send the payload data.
Otherwise `payload` is used as the payload buffer and sent. If
`payload_len` is not zero, it is used as the size of `payload`.
Otherwise `payload` is assumed to be a string and `strlen` is used to
determine its size. This is to maintain current behaviour and not break
existing samples.

Fixes #24431

Signed-off-by: Arvin Farahmand <arvinf@ip-logix.com>
hakehuang pushed a commit to hakehuang/zephyr that referenced this issue Jun 20, 2020
Bug fix and improved `payload` handling in `http_client_req`.

Changes to `http_client_req` behaviour:

If the user provides `payload_len` it is used to generate the
`Content-Length` header. This is done even if `payload_cb` is used to
provide the actual data. If no `payload_len` is specified then no
`Content-Length` is generated.

If `payload_cb` is provided it is called to send the payload data.
Otherwise `payload` is used as the payload buffer and sent. If
`payload_len` is not zero, it is used as the size of `payload`.
Otherwise `payload` is assumed to be a string and `strlen` is used to
determine its size. This is to maintain current behaviour and not break
existing samples.

Fixes zephyrproject-rtos#24431

Signed-off-by: Arvin Farahmand <arvinf@ip-logix.com>
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 priority: medium Medium impact/importance bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants