@@ -150,7 +150,7 @@ void HTTPClient::clear()
150150 * @param https bool
151151 * @return success bool
152152 */
153- bool HTTPClient::begin (WiFiClient &client, String url) {
153+ bool HTTPClient::begin (WiFiClient &client, const String& url) {
154154#if HTTPCLIENT_1_1_COMPATIBLE
155155 if (_tcpDeprecated) {
156156 DEBUG_HTTPCLIENT (" [HTTP-Client][begin] mix up of new and deprecated api\n " );
@@ -188,7 +188,7 @@ bool HTTPClient::begin(WiFiClient &client, String url) {
188188 * @param https bool
189189 * @return success bool
190190 */
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)
192192{
193193#if HTTPCLIENT_1_1_COMPATIBLE
194194 if (_tcpDeprecated) {
@@ -281,8 +281,10 @@ bool HTTPClient::begin(String url)
281281}
282282#endif // HTTPCLIENT_1_1_COMPATIBLE
283283
284- bool HTTPClient::beginInternal (String url , const char * expectedProtocol)
284+ bool HTTPClient::beginInternal (const String& __url , const char * expectedProtocol)
285285{
286+ String url (__url);
287+
286288 DEBUG_HTTPCLIENT (" [HTTP-Client][begin] url: %s\n " , url.c_str ());
287289 clear ();
288290
@@ -500,7 +502,7 @@ void HTTPClient::setAuthorization(const char * user, const char * password)
500502{
501503 if (user && password) {
502504 String auth = user;
503- auth += " : " ;
505+ auth += ' : ' ;
504506 auth += password;
505507 _base64Authorization = base64::encode (auth);
506508 }
@@ -533,7 +535,7 @@ void HTTPClient::setTimeout(uint16_t timeout)
533535 * set the URL to a new value. Handy for following redirects.
534536 * @param url
535537 */
536- bool HTTPClient::setURL (String url)
538+ bool HTTPClient::setURL (const String& url)
537539{
538540 // if the new location is only a path then only update the URI
539541 if (url && url[0 ] == ' /' ) {
@@ -542,7 +544,7 @@ bool HTTPClient::setURL(String url)
542544 return true ;
543545 }
544546
545- if (!url.startsWith (_protocol + " : " )) {
547+ if (!url.startsWith (_protocol + ' : ' )) {
546548 DEBUG_HTTPCLIENT (" [HTTP-Client][setURL] new URL not the same protocol, expected '%s', URL: '%s'\n " , _protocol.c_str (), url.c_str ());
547549 return false ;
548550 }
@@ -587,16 +589,16 @@ int HTTPClient::GET()
587589
588590/* *
589591 * sends a post request to the server
590- * @param payload uint8_t *
592+ * @param payload const uint8_t *
591593 * @param size size_t
592594 * @return http code
593595 */
594- int HTTPClient::POST (uint8_t * payload, size_t size)
596+ int HTTPClient::POST (const uint8_t * payload, size_t size)
595597{
596598 return sendRequest (" POST" , payload, size);
597599}
598600
599- int HTTPClient::POST (String payload)
601+ int HTTPClient::POST (const String& payload)
600602{
601603 return POST ((uint8_t *) payload.c_str (), payload.length ());
602604}
@@ -607,26 +609,26 @@ int HTTPClient::POST(String payload)
607609 * @param size size_t
608610 * @return http code
609611 */
610- int HTTPClient::PUT (uint8_t * payload, size_t size) {
612+ int HTTPClient::PUT (const uint8_t * payload, size_t size) {
611613 return sendRequest (" PUT" , payload, size);
612614}
613615
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 ());
616618}
617619
618620/* *
619621 * sends a patch request to the server
620- * @param payload uint8_t *
622+ * @param payload const uint8_t *
621623 * @param size size_t
622624 * @return http code
623625 */
624- int HTTPClient::PATCH (uint8_t * payload, size_t size) {
626+ int HTTPClient::PATCH (const uint8_t * payload, size_t size) {
625627 return sendRequest (" PATCH" , payload, size);
626628}
627629
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 ());
630632}
631633
632634/* *
@@ -635,19 +637,19 @@ int HTTPClient::PATCH(String payload) {
635637 * @param payload String data for the message body
636638 * @return
637639 */
638- int HTTPClient::sendRequest (const char * type, String payload)
640+ int HTTPClient::sendRequest (const char * type, const String& payload)
639641{
640- return sendRequest (type, (uint8_t *) payload.c_str (), payload.length ());
642+ return sendRequest (type, (const uint8_t *) payload.c_str (), payload.length ());
641643}
642644
643645/* *
644646 * 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
648650 * @return -1 if no info or > 0 when Content-Length is set by server
649651 */
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)
651653{
652654 bool redirect = false ;
653655 int code = 0 ;
@@ -1212,12 +1214,12 @@ bool HTTPClient::sendHeader(const char * type)
12121214 return false ;
12131215 }
12141216
1215- String header = String (type) + " " + (_uri.length () ? _uri : F (" /" )) + F (" HTTP/1." );
1217+ String header = String (type) + ' ' + (_uri.length () ? _uri : F (" /" )) + F (" HTTP/1." );
12161218
12171219 if (_useHTTP10) {
1218- header += " 0 " ;
1220+ header += ' 0 ' ;
12191221 } else {
1220- header += " 1 " ;
1222+ header += ' 1 ' ;
12211223 }
12221224
12231225 header += String (F (" \r\n Host: " )) + _host;
@@ -1316,7 +1318,8 @@ int HTTPClient::handleHeaderResponse()
13161318 if (_currentHeaders[i].key .equalsIgnoreCase (headerName)) {
13171319 if (_currentHeaders[i].value != " " ) {
13181320 // Existing value, append this one with a comma
1319- _currentHeaders[i].value += " ," + headerValue;
1321+ _currentHeaders[i].value += ' ,' ;
1322+ _currentHeaders[i].value += headerValue;
13201323 } else {
13211324 _currentHeaders[i].value = headerValue;
13221325 }
0 commit comments