Skip to content

webserver :Please add chunkedResponseModeStart / chunkedResponseFinalize #5080

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

Open
fanfanlatulipe26 opened this issue Apr 19, 2021 · 19 comments
Labels
Area: ESP-IDF related ESP-IDF related issues Type: Feature request Feature request for Arduino ESP32

Comments

@fanfanlatulipe26
Copy link

fanfanlatulipe26 commented Apr 19, 2021

Description:

webserver :Please add chunkedResponseModeStart / chunkedResponseFinalize
These functions were added in a recent release for ESP8266WebServer and it will be nice to have them in the upcomming release for ESP32. If not , porting from ESP8266 to ESP32 becomes cumbersome.
I developed a small derivated class to get them in rhe ESP32 environment. If it can help .....

Sketch:

#ifndef FS_WEBSERVER_H
#define FS_WEBSERVER_H

#include <WebServer.h>
class fs_WebServer : public WebServer
{
  public:
    fs_WebServer(int port = 80): WebServer(port) {
    }
   using WebServer:: send_P;
    void send_P(int code, PGM_P content_type, PGM_P content) {
      size_t contentLength = 0;

      if (content != NULL) {
        contentLength = strlen_P(content);
      }

      String header;
      char type[64];
      memccpy_P((void*)type, (PGM_VOID_P)content_type, 0, sizeof(type));
      _prepareHeader(header, code, (const char* )type, contentLength);
      _currentClientWrite(header.c_str(), header.length());
      if (contentLength) {  // if rajouté par FS ...........................+++++
        sendContent_P(content);
      }
    }

    bool chunkedResponseModeStart_P (int code, PGM_P content_type) {
      if (_currentVersion == 0)
        // no chunk mode in HTTP/1.0
        return false;
      setContentLength(CONTENT_LENGTH_UNKNOWN);
      send_P(code, content_type, "");
      return true;
    }
    bool chunkedResponseModeStart (int code, const char* content_type) {
      return chunkedResponseModeStart_P(code, content_type);
    }
    bool chunkedResponseModeStart (int code, const String& content_type) {
      return chunkedResponseModeStart_P(code, content_type.c_str());
    }
    void chunkedResponseFinalize () {
      sendContent(emptyString);
    }
};
#endif // FS_WEBSERVER_H
@VojtechBartoska VojtechBartoska added the Type: Feature request Feature request for Arduino ESP32 label Apr 21, 2021
@VojtechBartoska
Copy link
Contributor

Thanks @fanfanlatulipe26 . We will take a look and consider implementation.

@tablatronix
Copy link
Contributor

Status of this?

@fanfanlatulipe26
Copy link
Author

I just updated the code of the derivative class
using WebServer:: send_P;
was added.

@VojtechBartoska VojtechBartoska added the Status: Awaiting triage Issue is waiting for triage label Apr 11, 2022
@FrankBoesing
Copy link
Contributor

Any progress here?

@VojtechBartoska
Copy link
Contributor

Hello, no progress. I'm adding this to next release and we will triage this and let you know about the resolution.

@FrankBoesing
Copy link
Contributor

Great news!

@armazenamentoURL
Copy link

I really need this, I need to answer a gigantic (100mb) text file that is dynamically generated from memory. With esp8266 I sent with sendContent_P a few lines at a time and it worked great. I can't do this with esp32.
Thanks.

@fanfanlatulipe26
Copy link
Author

@AlefRosa
In the mean time, why don't you use my trick I gave at the beginning: just include in your sketch a file fs_Webserver.h containing the code I gave above and declare you server as fs_Webserver.
You can see the use in the project BaliseDGAC_GPS_Logger where you will find the file fs_Webserver.h and the server declaration and use in the .ino

@FrankBoesing
Copy link
Contributor

FrankBoesing commented May 21, 2023

Do you know how to use the  RequestHandler (server->addHandler(new ... ) with your derived class?

Btw, the ESP32 Request handler uses different arguments fr its methods :(

@FrankBoesing
Copy link
Contributor

FrankBoesing commented May 21, 2023

An other missing method is:

void send(int code, const char *content_type, const char *content, size_t contentLength)
Without, it uses an often superlfues strlen(), which is not optimal (esp with large content)
Esp8266 has it.

@fanfanlatulipe26
Copy link
Author

Sorry, I never used RequestHandler . I had a look at the source code for RequestHandler .h and the ESP8266 version is really more C++ that the ESP32 one. I must admit that I am not C++ expert ... Didn't find any examples.

@armazenamentoURL
Copy link

@fanfanlatulipe26 thank you very much, i got it yesterday. As I need to use asyncwebserver, I studied it further and managed to use request response using chunk method. thank you so much again! Now I'm managing to generate 10mb files from memory registers and send them in parts as I make them.

@VojtechBartoska VojtechBartoska added the Area: ESP-IDF related ESP-IDF related issues label Sep 25, 2023
@chconnor
Copy link

Also eagerly awaiting this important feature!

Thanks @fanfanlatulipe26 -- that code worked great. I had to add an additional constructor at the top:

fs_WebServer(IPAddress addr, int port): WebServer(addr, port){ }

@fanfanlatulipe26
Copy link
Author

Thanks @chconnor for the tip. I updated the code in the repository BaliseDGAC_GPS_Logger that I referenced above. It may help some one.

@FarokhReza
Copy link

Thanks for sharing it is great for solving some issues in the progress of migration from esp8266 to esp32!!

@VojtechBartoska VojtechBartoska modified the milestones: 3.0.0, 3.1.0 Feb 20, 2024
@VojtechBartoska
Copy link
Contributor

Postponing to 3.1.0 Milestone, we will cover this during Webserver refactoring

@rftafas rftafas modified the milestones: 3.1.0, 3.1.1 Jan 6, 2025
@rftafas rftafas removed this from the 3.1.1 milestone Jan 14, 2025
@Parsaabasi Parsaabasi removed the Status: Awaiting triage Issue is waiting for triage label Jan 16, 2025
@Parsaabasi
Copy link

Hello,

Due to the overwhelming volume of issues currently being addressed, we have decided to close the previously received tickets. If you still require assistance or if the issue persists, please don't hesitate to reopen the ticket.

Thanks.

@chconnor
Copy link

@VojtechBartoska -- did you folks happen to get this done in the Webserver refactoring, or should it be reopened? (I didn't see it in the closed issues for the milestones linked above, or for 3.2.0.)

@chconnor
Copy link

I have confirmed that WebServer.h still does not have this included. I don't have permission to reopen this issue -- perhaps someone else can?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: ESP-IDF related ESP-IDF related issues Type: Feature request Feature request for Arduino ESP32
Projects
Development

No branches or pull requests

11 participants