HttpRequestComponent::get_string - avoid copy (#2988)

This commit is contained in:
Roi Tagar 2022-02-17 06:03:54 +02:00 committed by GitHub
parent 36ddd9dd69
commit 958ad0d750
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -120,10 +120,16 @@ void HttpRequestComponent::close() {
} }
const char *HttpRequestComponent::get_string() { const char *HttpRequestComponent::get_string() {
// The static variable is here because HTTPClient::getString() returns a String on ESP32, and we need something to #if defined(ESP32)
// to keep a buffer alive. // The static variable is here because HTTPClient::getString() returns a String on ESP32,
static std::string str; // and we need something to keep a buffer alive.
str = this->client_.getString().c_str(); static String str;
#else
// However on ESP8266, HTTPClient::getString() returns a String& to a member variable.
// Leaving this the default so that any new platform either doesn't copy, or encounters a compilation error.
auto &
#endif
str = this->client_.getString();
return str.c_str(); return str.c_str();
} }