khoih-prog / EthernetWebServer_SSL

Simple TLS/SSL Ethernet WebServer, HTTP Client and WebSocket Client library for for AVR, Portenta_H7, Teensy, SAM DUE, SAMD21, SAMD51, STM32F/L/H/G/WB/MP1, nRF52 and RASPBERRY_PI_PICO boards using Ethernet shields W5100, W5200, W5500, ENC28J60 or Teensy 4.1 NativeEthernet/QNEthernet. It now supports Ethernet TLS/SSL Client. The library supports HTTP/HTTPS GET and POST requests, provides argument parsing, handles one client at a time. It supports Arduino boards (SAM DUE, Atmel SAM3X8E ARM Cortex-M3, SAMD21, SAMD51, ESP8266, ESP32, Adafruit nRF52, Teensy boards) using Wiznet W5x00 or ENC28J60 network shields. Ethernet_Generic library is used as default for W5x00 with custom SPI
GNU General Public License v3.0
46 stars 10 forks source link

Buffer limitation? #6

Closed gitTinker closed 3 years ago

gitTinker commented 3 years ago

When I run this PoC code the browser console states: net::ERR_CONTENT_LENGTH_MISMATCH 200 (OK)

If just one character is removed, no error occurs.

The size of the variable containing the contents is 2050. I have set #define SENDCONTENT_P_BUFFER_SZ 6144 (event though the default 4096 should be sufficient)

The PoC attached here is merely the example, with the handelRoot function replaced, the inclusion of a file, and these lines:

#include "index_html.h"
#define SENDCONTENT_P_BUFFER_SZ 6144

void handleRoot() {
  Serial.print(F("SENDCONTENT_P_BUFFER_SZ: ")); Serial.println(SENDCONTENT_P_BUFFER_SZ);
  Serial.print(F("INDEX_HTML: ")); Serial.println(sizeof(INDEX_HTML));
  server.send(200, "text/html", INDEX_HTML);
}

(remove the .txt extension to use the files)

AdvancedWebServer_NativeEthernet_BufferError.ino.txt defines.h.txt index_html.h.txt

The same HTML opened directly into the browser has no errors.

gitTinker commented 3 years ago

I am using a Featherwing M4 (SAMD51) with the NIC (W5x00)

EthernetWebServer_SSL v1.5.0 Arduino IDE 1.8.15

khoih-prog commented 3 years ago

I tested the code and see no issue even with buffer size larger = 2075 bytes

Selection_819

I suggest if you have more issue, spend some more time to test, research before posting something too early. A good programmer is expected at least to ( code <-> test <-> investigate <-> research ) before surrender so soon.

Moreover, this library is just a wrapper on top of the Ethernet (Ethernet, EthernetLarge, Ethernet2, Ethernet3, etc) libraries and inherits all the related limitation. And many times the buffer size as well as handling can cause some issues.

It's also better that you start over and test using directly the Ethernet libraries, and see if there is any issue caused by them.

Unless you prove the bug is in this library, I'm closing the issue now.

gitTinker commented 3 years ago

Am I using the buffer size correctly? Is this a buffer issue?

gitTinker commented 3 years ago

Thank you for investigating; every new bit of info helps. Even the stereo-typical response of 'it works on my end' eliminates some variables.

Least you think I am an ignoramus, I am attaching a screenshot of the message in my browser. temp

gitTinker commented 3 years ago

Thanks also for the suggestion to check the root library; this behavior occurs there too. You are right, your updates did NOT introduce this behavior.

If it helps others, the very privative library from Arduino does not have the behavior mentioned above. But Khoi's library is far more convenient to use

gitTinker commented 3 years ago

I found a work-around that lets me continue to use this very excellent library for most content, with a workaround for really big pages.

@khoih-prog, I think the limitation may be with the hardware. I do not have any limitation with an ESP8266, but with this shield, on this M4, I can only send up to 2050 characters - no matter what the SENDCONTENT_P_BUFFER_SZ is set to. The key part of my functional example is sending in smaller chunks

  while (chunkStart < strlen(IMAGE_SVG)) {
    strncpy ( chunk, &IMAGE_SVG[chunkStart], maxSendBufferSize );
    chunk[maxSendBufferSize] = '\0';  // ensure null terminated
    client.print(chunk);
    chunkStart += maxSendBufferSize;

temp

@khoih-prog, doesn't look like there is anything you can 'fix', so no expectation to re-open this

AdvancedWebServer_NativeEthernet_BufferWorkAround.ino.txt defines.h.txt index_html.h.txt

khoih-prog commented 3 years ago

It's good that you found the temporary way out.

Did you try to increase the buffer by follow For application requiring 2K+ HTML page ?

gitTinker commented 3 years ago

😲 again I learn something new! I've read through the readme many times, but the relevance of that section just didn't occur to me....

However, the example I used is a 5K page and I like having a few simultaneous connections. Reading your notes I could likely get up to 6K by dropping to a single socket but I am also running your websockets for automation and I think I'll leave as-is for this project.

I've left myself a note in my build instructions to try your Ethernet modifications for my next proj.

khoih-prog commented 3 years ago

I used to have that bad habit when still very young. But as time goes by, I've realized it's much more efficient and not wasting time by not reinventing everything. Then I've always tried to learn from other people's experience / works by reading carefully the docs / books and use / apply as much as I could.