Skip to content

MG_EV_HTTP_MSG not triggered on TLS + chunked responses #3104

Open
@GhoweVege

Description

@GhoweVege
  • My goal is: Send and receive data from an ESP32 to a server using TLS and chunked encoding.
  • My actions were: I programmed an ESP32 to send an update to a remote server that uses TLS and chunked encoding.
  • My expectation was: That Mongoose would trigger MG_EV_HTTP_MSG when the full response, including the terminating chunk, was received and buffered, even when delivered over TLS.
  • The result I saw: MG_EV_HTTP_MSG was not triggered. Only MG_EV_CLOSE fired, and the buffered data contained the full HTTP response. This only happens when TLS and chunked encoding are both used. Plain HTTP with chunked encoding works fine. TLS with non-chunked responses also works fine.
  • My question is: Can the logic in the read_conn() function be changed to be closer to what was used in 7.15 so that MG_EV_HTTP_MSG gets triggered after the final terminating chunk arrives.

Environment

  • mongoose version: 7.15, 7.16, 7.17
  • Compiler/IDE and SDK: PlatformIO with ESP32 Arduino framework
  • Target hardware/board: ESP32
  • Connectivity chip/module: onboard WiFi (ESP32)
  • Target RTOS/OS (if applicable): Arduino (no RTOS)

Overview

The original failure was observed after upgrading from 7.15 to 7.17 when sending updates from an ESP32 to a remote logging server.

I made a test server and ran lots of tests to narrow down exactly what is happening, and the MG_EV_HTTP_MSG only fails to trigger in one specific scenario: it fails when the server being contacted uses TLS and the response uses chunked encoding.

I tested further until I narrowed down the problem to a change in the logic used in the read_conn() function between versions 7.15 and 7.16.

I tested using the latest version (7.17), and just changing the logic of read_conn() back to what it was in 7.15, and that resolves the issue.

If you want it, I have minimal code that proves the failure, but you can probably make your own just as easily. On the ESP32 side, it is just a client that sends a request to a server and watches for the reply. The server side is a simple python server that can respond using chunked or normal encoding, and can toggle whether or not to use TLS.

My temporary workaround has been that when I get a 'MG_EV_CLOSE' event in my code, I check to see if I have received a response from the server, and if not, manually trigger a 'mg_http_parse()' on the receive buffer to see if there is valid data, and if so, I trigger a 'MG_EV_HTTP_MSG'.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions