Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion libraries/ESP8266WebServer/src/ESP8266WebServer-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ void ESP8266WebServerTemplate<ServerType>::stop() {
}

template <typename ServerType>
void ESP8266WebServerTemplate<ServerType>::sendHeader(String&& name, String&& value, bool first) {
template <typename S1, typename S2>
void ESP8266WebServerTemplate<ServerType>::sendHeader(S1 name, S2 value, bool first) {
Copy link
Collaborator

@mcspr mcspr Feb 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit

at a glance, we have a bunch of typed pairs that generate multiple emplace_... for every sendHeader variant
I'd consider using perfect forward and a specific type we already have

using Pair = std::pair<String, String>;

auto foo(Pair pair, bool condition) {
    if (condition) {
        foo(std::move(pair));
    } else {
        bar(std::move(pair));
    }
}

template <typename S1, typename S2>
auto foo(S1&& name, S2&& value, bool condition) {
    foo(std::make_pair(
        String(std::forward<S1>(name)),
        String(std::forward<S2>(value)), condition);
}

if (first)
_userHeaders.emplace_front(std::pair(name, value));
else
Expand Down
4 changes: 2 additions & 2 deletions libraries/ESP8266WebServer/src/ESP8266WebServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ class ESP8266WebServerTemplate
}

void setContentLength(const size_t contentLength);
void sendHeader(String&& name, String&& value, bool first = false);
void sendHeader(const String& name, const String& value, bool first = false);
template <typename S1, typename S2>
void sendHeader(S1 name, S2 value, bool first = false);
void sendContent(const String& content);
void sendContent(String& content) {
sendContent((const String&)content);
Expand Down