@@ -150,7 +150,7 @@ void HTTPClient::clear()
150
150
* @param https bool
151
151
* @return success bool
152
152
*/
153
- bool HTTPClient::begin (WiFiClient &client, String url) {
153
+ bool HTTPClient::begin (WiFiClient &client, const String& url) {
154
154
#if HTTPCLIENT_1_1_COMPATIBLE
155
155
if (_tcpDeprecated) {
156
156
DEBUG_HTTPCLIENT (" [HTTP-Client][begin] mix up of new and deprecated api\n " );
@@ -188,7 +188,7 @@ bool HTTPClient::begin(WiFiClient &client, String url) {
188
188
* @param https bool
189
189
* @return success bool
190
190
*/
191
- bool HTTPClient::begin (WiFiClient &client, String host, uint16_t port, String uri, bool https)
191
+ bool HTTPClient::begin (WiFiClient &client, const String& host, uint16_t port, const String& uri, bool https)
192
192
{
193
193
#if HTTPCLIENT_1_1_COMPATIBLE
194
194
if (_tcpDeprecated) {
@@ -281,8 +281,10 @@ bool HTTPClient::begin(String url)
281
281
}
282
282
#endif // HTTPCLIENT_1_1_COMPATIBLE
283
283
284
- bool HTTPClient::beginInternal (String url , const char * expectedProtocol)
284
+ bool HTTPClient::beginInternal (const String& __url , const char * expectedProtocol)
285
285
{
286
+ String url (__url);
287
+
286
288
DEBUG_HTTPCLIENT (" [HTTP-Client][begin] url: %s\n " , url.c_str ());
287
289
clear ();
288
290
@@ -500,7 +502,7 @@ void HTTPClient::setAuthorization(const char * user, const char * password)
500
502
{
501
503
if (user && password) {
502
504
String auth = user;
503
- auth += " : " ;
505
+ auth += ' : ' ;
504
506
auth += password;
505
507
_base64Authorization = base64::encode (auth);
506
508
}
@@ -533,7 +535,7 @@ void HTTPClient::setTimeout(uint16_t timeout)
533
535
* set the URL to a new value. Handy for following redirects.
534
536
* @param url
535
537
*/
536
- bool HTTPClient::setURL (String url)
538
+ bool HTTPClient::setURL (const String& url)
537
539
{
538
540
// if the new location is only a path then only update the URI
539
541
if (url && url[0 ] == ' /' ) {
@@ -542,7 +544,7 @@ bool HTTPClient::setURL(String url)
542
544
return true ;
543
545
}
544
546
545
- if (!url.startsWith (_protocol + " : " )) {
547
+ if (!url.startsWith (_protocol + ' : ' )) {
546
548
DEBUG_HTTPCLIENT (" [HTTP-Client][setURL] new URL not the same protocol, expected '%s', URL: '%s'\n " , _protocol.c_str (), url.c_str ());
547
549
return false ;
548
550
}
@@ -587,16 +589,16 @@ int HTTPClient::GET()
587
589
588
590
/* *
589
591
* sends a post request to the server
590
- * @param payload uint8_t *
592
+ * @param payload const uint8_t *
591
593
* @param size size_t
592
594
* @return http code
593
595
*/
594
- int HTTPClient::POST (uint8_t * payload, size_t size)
596
+ int HTTPClient::POST (const uint8_t * payload, size_t size)
595
597
{
596
598
return sendRequest (" POST" , payload, size);
597
599
}
598
600
599
- int HTTPClient::POST (String payload)
601
+ int HTTPClient::POST (const String& payload)
600
602
{
601
603
return POST ((uint8_t *) payload.c_str (), payload.length ());
602
604
}
@@ -607,26 +609,26 @@ int HTTPClient::POST(String payload)
607
609
* @param size size_t
608
610
* @return http code
609
611
*/
610
- int HTTPClient::PUT (uint8_t * payload, size_t size) {
612
+ int HTTPClient::PUT (const uint8_t * payload, size_t size) {
611
613
return sendRequest (" PUT" , payload, size);
612
614
}
613
615
614
- int HTTPClient::PUT (String payload) {
615
- return PUT ((uint8_t *) payload.c_str (), payload.length ());
616
+ int HTTPClient::PUT (const String& payload) {
617
+ return PUT ((const uint8_t *) payload.c_str (), payload.length ());
616
618
}
617
619
618
620
/* *
619
621
* sends a patch request to the server
620
- * @param payload uint8_t *
622
+ * @param payload const uint8_t *
621
623
* @param size size_t
622
624
* @return http code
623
625
*/
624
- int HTTPClient::PATCH (uint8_t * payload, size_t size) {
626
+ int HTTPClient::PATCH (const uint8_t * payload, size_t size) {
625
627
return sendRequest (" PATCH" , payload, size);
626
628
}
627
629
628
- int HTTPClient::PATCH (String payload) {
629
- return PATCH ((uint8_t *) payload.c_str (), payload.length ());
630
+ int HTTPClient::PATCH (const String& payload) {
631
+ return PATCH ((const uint8_t *) payload.c_str (), payload.length ());
630
632
}
631
633
632
634
/* *
@@ -635,19 +637,19 @@ int HTTPClient::PATCH(String payload) {
635
637
* @param payload String data for the message body
636
638
* @return
637
639
*/
638
- int HTTPClient::sendRequest (const char * type, String payload)
640
+ int HTTPClient::sendRequest (const char * type, const String& payload)
639
641
{
640
- return sendRequest (type, (uint8_t *) payload.c_str (), payload.length ());
642
+ return sendRequest (type, (const uint8_t *) payload.c_str (), payload.length ());
641
643
}
642
644
643
645
/* *
644
646
* sendRequest
645
- * @param type const char * "GET", "POST", ....
646
- * @param payload uint8_t * data for the message body if null not send
647
- * @param size size_t size for the message body if 0 not send
647
+ * @param type const char * "GET", "POST", ....
648
+ * @param payload const uint8_t * data for the message body if null not send
649
+ * @param size size_t size for the message body if 0 not send
648
650
* @return -1 if no info or > 0 when Content-Length is set by server
649
651
*/
650
- int HTTPClient::sendRequest (const char * type, uint8_t * payload, size_t size)
652
+ int HTTPClient::sendRequest (const char * type, const uint8_t * payload, size_t size)
651
653
{
652
654
bool redirect = false ;
653
655
int code = 0 ;
@@ -1212,12 +1214,12 @@ bool HTTPClient::sendHeader(const char * type)
1212
1214
return false ;
1213
1215
}
1214
1216
1215
- String header = String (type) + " " + (_uri.length () ? _uri : F (" /" )) + F (" HTTP/1." );
1217
+ String header = String (type) + ' ' + (_uri.length () ? _uri : F (" /" )) + F (" HTTP/1." );
1216
1218
1217
1219
if (_useHTTP10) {
1218
- header += " 0 " ;
1220
+ header += ' 0 ' ;
1219
1221
} else {
1220
- header += " 1 " ;
1222
+ header += ' 1 ' ;
1221
1223
}
1222
1224
1223
1225
header += String (F (" \r\n Host: " )) + _host;
@@ -1316,7 +1318,8 @@ int HTTPClient::handleHeaderResponse()
1316
1318
if (_currentHeaders[i].key .equalsIgnoreCase (headerName)) {
1317
1319
if (_currentHeaders[i].value != " " ) {
1318
1320
// Existing value, append this one with a comma
1319
- _currentHeaders[i].value += " ," + headerValue;
1321
+ _currentHeaders[i].value += ' ,' ;
1322
+ _currentHeaders[i].value += headerValue;
1320
1323
} else {
1321
1324
_currentHeaders[i].value = headerValue;
1322
1325
}
0 commit comments