-
-
Notifications
You must be signed in to change notification settings - Fork 345
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
Improve Vector
and HttpHeaders
iteration
#2745
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -367,9 +367,9 @@ void HttpClientConnection::sendRequestHeaders(HttpRequest* request) | |
request->headers[HTTP_HEADER_TRANSFER_ENCODING] = _F("chunked"); | ||
} | ||
|
||
for(unsigned i = 0; i < request->headers.count(); i++) { | ||
for(auto hdr : request->headers) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please rename |
||
// TODO: add name and/or value escaping (implement in HttpHeaders) | ||
sendString(request->headers[i]); | ||
sendString(hdr); | ||
} | ||
sendString("\r\n"); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,25 @@ | |
#include "HttpHeaders.h" | ||
#include <debug_progmem.h> | ||
|
||
String HttpHeaders::HeaderConst::getFieldName() const | ||
{ | ||
return fields.toString(key()); | ||
} | ||
|
||
size_t HttpHeaders::HeaderConst::printTo(Print& p) const | ||
{ | ||
size_t n{0}; | ||
n += p.print(getFieldName()); | ||
n += p.print(" = "); | ||
n += p.print(value()); | ||
return n; | ||
} | ||
|
||
HttpHeaders::HeaderConst::operator String() const | ||
{ | ||
return fields.toString(key(), value()); | ||
} | ||
|
||
const String& HttpHeaders::operator[](const String& name) const | ||
{ | ||
auto field = fromString(name); | ||
|
@@ -40,9 +59,7 @@ bool HttpHeaders::append(const HttpHeaderFieldName& name, const String& value) | |
|
||
void HttpHeaders::setMultiple(const HttpHeaders& headers) | ||
{ | ||
for(unsigned i = 0; i < headers.count(); i++) { | ||
HttpHeaderFieldName fieldName = headers.keyAt(i); | ||
auto fieldNameString = headers.toString(fieldName); | ||
operator[](fieldNameString) = headers.valueAt(i); | ||
for(auto hdr : headers) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
operator[](hdr.getFieldName()) = hdr.value(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,8 +77,8 @@ String HttpRequest::toString() const | |
if(!headers.contains(HTTP_HEADER_HOST)) { | ||
content += headers.toString(HTTP_HEADER_HOST, uri.getHostWithPort()); | ||
} | ||
for(unsigned i = 0; i < headers.count(); i++) { | ||
content += headers[i]; | ||
for(auto hdr : headers) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
content += hdr; | ||
} | ||
|
||
if(!headers.contains(HTTP_HEADER_CONTENT_LENGTH)) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,8 +137,8 @@ String HttpResponse::toString() const | |
content += ' '; | ||
content += ::toString(code); | ||
content += " \r\n"; | ||
for(unsigned i = 0; i < headers.count(); i++) { | ||
content += headers[i]; | ||
for(auto hdr : headers) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
content += hdr; | ||
} | ||
content += "\r\n"; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -312,8 +312,8 @@ void HttpServerConnection::sendResponseHeaders(HttpResponse* response) | |
response->headers[HTTP_HEADER_DATE] = DateTime(SystemClock.now(eTZ_UTC)).toHTTPDate(); | ||
} | ||
|
||
for(unsigned i = 0; i < response->headers.count(); i++) { | ||
sendString(response->headers[i]); | ||
for(auto hdr : response->headers) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
sendString(hdr); | ||
} | ||
sendString("\r\n"); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -292,9 +292,9 @@ void WebsocketConnection::broadcast(const char* message, size_t length, ws_frame | |
memcpy(copy, message, length); | ||
std::shared_ptr<const char> data(copy, [](const char* ptr) { delete[] ptr; }); | ||
|
||
for(unsigned i = 0; i < websocketList.count(); i++) { | ||
for(auto skt : websocketList) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
auto stream = new SharedMemoryStream<const char>(data, length); | ||
websocketList[i]->send(stream, type); | ||
skt->send(stream, type); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -306,8 +306,8 @@ void SmtpClient::sendMailHeaders(MailMessage* mail) | |
mail->stream = mStream; | ||
} | ||
|
||
for(unsigned i = 0; i < mail->headers.count(); i++) { | ||
sendString(mail->headers[i]); | ||
for(auto hdr : mail->headers) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
sendString(hdr); | ||
} | ||
sendString("\r\n"); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,8 +40,8 @@ int onDownload(HttpConnection& connection, bool success) | |
Serial << _F(", received ") << stream->available() << _F(" bytes") << endl; | ||
|
||
auto& headers = connection.getResponse()->headers; | ||
for(unsigned i = 0; i < headers.count(); ++i) { | ||
Serial.print(headers[i]); | ||
for(auto hdr : headers) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
Serial.print(hdr); | ||
} | ||
|
||
auto ssl = connection.getSsl(); | ||
|
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.
cmd
->command