Skip to content
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

@timw1971
Copy link
Contributor

timw1971 commented Aug 3, 2017

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.

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.
@timw1971 timw1971 changed the title Add files via upload ESP8266WebServer minor public interface addition - content from const char* Aug 3, 2017
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);

This comment has been minimized.

Copy link
@igrr

igrr Sep 21, 2017

Member

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) {

This comment has been minimized.

Copy link
@igrr

igrr Sep 21, 2017

Member

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.

@earlephilhower

This comment has been minimized.

Copy link
Collaborator

earlephilhower commented Oct 1, 2019

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?

earlephilhower added a commit to earlephilhower/Arduino that referenced this pull request Nov 17, 2019
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.
@earlephilhower

This comment has been minimized.

Copy link
Collaborator

earlephilhower commented Nov 17, 2019

Replaced with #6797

devyte added a commit that referenced this pull request Nov 19, 2019
* 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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.