diff --git a/code/espurna/libs/Http.h b/code/espurna/libs/Http.h index bc8decdf72..9b95fbf7fe 100644 --- a/code/espurna/libs/Http.h +++ b/code/espurna/libs/Http.h @@ -234,7 +234,7 @@ class AsyncHttp { + http->host.length() + http->path.length() + 32; - std::unique_ptr headers(new (std::nothrow) char[headers_len + 1]); + char* headers = (char *) malloc(headers_len + 1); if (!headers) { ASYNC_HTTP_DEBUG("err | alloc %u fail\n", headers_len + 1); @@ -242,7 +242,7 @@ class AsyncHttp { return; } - int res = snprintf_P(headers.get(), headers_len + 1, + int res = snprintf_P(headers, headers_len + 1, HTTP_REQUEST_TEMPLATE, http->method.c_str(), http->path.c_str(), @@ -251,11 +251,14 @@ class AsyncHttp { ); if (res >= (headers_len + 1)) { ASYNC_HTTP_DEBUG("err | res>=len :: %u>=%u\n", res, headers_len + 1); + free(headers); client->close(true); return; } - client->write(headers.get()); + client->write(headers); + // TODO: streaming data source instead of using a simple String + // TODO: move to onPoll, ->add(data) and ->send() until it can't (returns 0), then repeat client->write(http->data.c_str()); }