Skip to content

Commit 0667227

Browse files
committed
Issue #5: a few more F(), and better string construction
1 parent d17bf72 commit 0667227

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

src/UniversalTelegramBot.cpp

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ String UniversalTelegramBot::sendGetToTelegram(String command) {
8484
String a = "";
8585
char c;
8686
int ch_count = 0;
87-
client->println("GET /" + command);
87+
client->print(F("GET /"));
88+
client->println(command);
8889
now = millis();
8990
avail = false;
9091
while (millis() - now < longPoll * 1000 + waitForResponse) {
@@ -130,11 +131,11 @@ String UniversalTelegramBot::sendPostToTelegram(String command, JsonObject paylo
130131
}
131132
if (client->connected()) {
132133
// POST URI
133-
client->print("POST /" + command);
134+
client->print(F("POST /"));
135+
client->print(command);
134136
client->println(F(" HTTP/1.1"));
135137
// Host header
136-
client->print(F("Host:"));
137-
client->println(HOST);
138+
client->println(F("Host:" HOST));
138139
// JSON content type
139140
client->println(F("Content-Type: application/json"));
140141

@@ -221,22 +222,27 @@ String UniversalTelegramBot::sendMultipartFormDataToTelegram(
221222
}
222223
if (client->connected()) {
223224

224-
String start_request = "";
225-
String end_request = "";
226-
227-
start_request = start_request + "--" + boundry + "\r\n";
228-
start_request = start_request + "content-disposition: form-data; name=\"chat_id\"" + "\r\n";
229-
start_request = start_request + "\r\n";
230-
start_request = start_request + chat_id + "\r\n";
231-
start_request = start_request + "--" + boundry + "\r\n";
232-
start_request = start_request + "content-disposition: form-data; name=\"" + binaryProperyName + "\"; filename=\"" + fileName + "\"" + "\r\n";
233-
start_request = start_request + "Content-Type: " + contentType + "\r\n";
234-
start_request = start_request + "\r\n";
235-
236-
end_request = end_request + "\r\n";
237-
end_request = end_request + "--" + boundry + "--" + "\r\n";
238-
239-
client->print("POST /bot" + _token + "/" + command);
225+
String start_request = F("--");
226+
227+
start_request += boundry;
228+
start_request += F("\r\ncontent-disposition: form-data; name=\"chat_id\"\r\n\r\n");
229+
start_request += chat_id;
230+
start_request += F("\r\n" "--");
231+
start_request += boundry;
232+
start_request += F("\r\ncontent-disposition: form-data; name=\"");
233+
start_request += binaryProperyName;
234+
start_request += F("\"; filename=\"");
235+
start_request += fileName;
236+
start_request += F("\"\r\n" "Content-Type: ");
237+
start_request += contentType;
238+
start_request += F("\r\n" "\r\n");
239+
240+
String end_request = F("\r\n" "--");
241+
end_request += boundry;
242+
end_request += F("--" "\r\n");
243+
244+
client->print(F("POST /"));
245+
client->print(buildCommand(command));
240246
client->println(F(" HTTP/1.1"));
241247
// Host header
242248
client->print(F("Host: "));
@@ -248,10 +254,11 @@ String UniversalTelegramBot::sendMultipartFormDataToTelegram(
248254
#ifdef _debug
249255
Serial.println("Content-Length: " + String(contentLength));
250256
#endif
251-
client->print("Content-Length: ");
257+
client->print(F("Content-Length: "));
252258
client->println(String(contentLength));
253-
client->println("Content-Type: multipart/form-data; boundary=" + boundry);
254-
client->println("");
259+
client->print(F("Content-Type: multipart/form-data; boundary="));
260+
client->println(boundry);
261+
client->println(F(""));
255262
client->print(start_request);
256263

257264
#ifdef _debug

0 commit comments

Comments
 (0)