espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.87k stars 7.32k forks source link

esp_http_server: provide a method to send response preamble (IDFGH-13182) #14121

Open gudvinr opened 5 months ago

gudvinr commented 5 months ago

Is your feature request related to a problem?

When you want to create simplex S2C connection (for example, to use with SSE), you will need to construct the whole response preamble by hand.

Describe the solution you'd like.

Add a method to send only http preamble consists of status line and headers without sending body and closing connection.

This method can be used by:

Describe alternatives you've considered.

No response

Additional context.

No response

nileshkale123 commented 1 month ago

Hello @gudvinr,

Sorry for the late reply.

I'm not entirely clear on your specific requirements. Could you please elaborate in more detail?

I suggest providing some dummy code/patch file for the change you're asking for OR creating a PR where we can discuss it further and, if useful, we will merge it.

gudvinr commented 1 month ago

I'm not entirely clear on your specific requirements. Could you please elaborate in more detail?

Easiest to understand would be concept of server-sent events. In browsers, it is implemented by EventSource API.

Basically, it is one-way stream (server to client) of events.

In contrast to WebSocket, you don't need extra Upgrade flow and other stuff. It's basically what people call "long polling", but it doesn't finish after first reply.

nileshkale123 commented 3 weeks ago

Hello @gudvinr

We are already working on adding support for Server-Sent Events (SSE) in ESP-IDF, and the process is well underway. A Merge Request (MR) has already been raised to integrate SSE support along with a corresponding example.

For your convenience, I’ve attached the relevant patch file. Could you please review it and let us know if it meets your requirements? If you have additional expectations or specific needs, we’d be happy to discuss them further to ensure we align closely with your goals.

Thank you, and we look forward to your feedback.

sse_support.txt

gudvinr commented 1 week ago

In this patch I only see examples section so it's hard to say.

For my use-case there's no need for SSE specifically.

Basically I want to stream raw data from ESP and receive using e.g. readable stream API.

SSE is text-based protocol and I want binary data. But it's similar enough to what I want, so I used it as an example.