-
Notifications
You must be signed in to change notification settings - Fork 13.3k
ESP8266WebServer minor public interface addition - content from const char* #3492
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
ESP8266WebServer minor public interface addition - content from const char* #3492
Conversation
Added public functions to allow content to be uploaded using const char*. For some cases, this can remove the need for content to be copied into a String, and thus can be considerably more space-efficient.
void send(int code, const String& content_type, const String& content); | ||
void send_P(int code, PGM_P content_type, PGM_P content); | ||
void send_P(int code, PGM_P content_type, PGM_P content, size_t contentLength); | ||
|
||
void setContentLength(size_t contentLength); | ||
void sendHeader(const String& name, const String& value, bool first = false); | ||
void sendContent(const String& content); | ||
void sendContent(const char* content, size_t contentLength); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For many people programming in C, const char*
implies a zero-terminated string. Of course, it can also be used to pass arbitrary binary data, but most APIs i have seen use either const void*
or const uint8_t*
for this purpose. I would suggest changing the type here to hint that a null-terminated string is not expected.
void ESP8266WebServer::sendContent(const char* content, size_t contentLength) { | ||
const size_t unit_size = HTTP_DOWNLOAD_UNIT_SIZE; | ||
|
||
while (contentLength) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation does not match the one for sendContent(String&), which uses chunked encoding and leaves fragmentation to the lower level code (WiFiClient). It would be nice if this sendContent(data, size) and sendContent(String) would behave the same way.
Thanks for your PR, but the core and libraries have changed enough that this PR now has a merge conflict. Could you merge it manually with the latest core, so we can consider it for future releases? |
Supercedes esp8266#3492 Allow sending raw binary data or strings directly without conversion to a String to reduce memory overhead when possible. From original @timw1971 PR esp8266#3492 Added public functions to allow content to be uploaded using const char*. For some cases, this can remove the need for content to be copied into a String, and thus can be considerably more space-efficient.
Replaced with #6797 |
* Add const char* content to ESP8266WebSerer::send() Supercedes #3492 Allow sending raw binary data or strings directly without conversion to a String to reduce memory overhead when possible. From original @timw1971 PR #3492 Added public functions to allow content to be uploaded using const char*. For some cases, this can remove the need for content to be copied into a String, and thus can be considerably more space-efficient. * Fix example formatting * Make GIF example use static const array * Make the example really need to use const char* Make the generated GIF dynamic in the example and move the original to PROGMEM (since that's where const arrays like this belong).
Added public functions to allow content to be uploaded using const char*. For some cases, this can remove the need for content to be copied into a String, and thus can be considerably more space-efficient.