Skip to content

Commit cfbb730

Browse files
lonerzzzme-no-dev
authored andcommitted
Update to make use of SSL a bit less confusing by ensuring errors are generated if the wrong method is called to retrieve the data stream. (espressif#934)
1 parent 75bc1e6 commit cfbb730

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

libraries/HTTPClient/src/HTTPClient.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ bool HTTPClient::begin(String host, uint16_t port, String uri, const char* CAcer
203203
if (strlen(CAcert) == 0) {
204204
return false;
205205
}
206+
_secure = true;
206207
_transportTraits = TransportTraitsPtr(new TLSTraits(CAcert));
207208
return true;
208209
}
@@ -217,6 +218,7 @@ bool HTTPClient::begin(String host, uint16_t port, String uri, const char* CAcer
217218
if (strlen(CAcert) == 0) {
218219
return false;
219220
}
221+
_secure = true;
220222
_transportTraits = TransportTraitsPtr(new TLSTraits(CAcert, cli_cert, cli_key));
221223
return true;
222224
}
@@ -561,26 +563,26 @@ int HTTPClient::getSize(void)
561563
*/
562564
WiFiClient& HTTPClient::getStream(void)
563565
{
564-
if(connected()) {
566+
if (connected() && !_secure) {
565567
return *_tcp;
566568
}
567569

568-
log_d("getStream: not connected");
570+
log_w("getStream: not connected");
569571
static WiFiClient empty;
570572
return empty;
571573
}
572574

573575
/**
574-
* returns the stream of the tcp connection
575-
* @return WiFiClient *
576+
* returns a pointer to the stream of the tcp connection
577+
* @return WiFiClient*
576578
*/
577579
WiFiClient* HTTPClient::getStreamPtr(void)
578580
{
579581
if(connected()) {
580582
return _tcp.get();
581583
}
582584

583-
log_d("getStreamPtr: not connected");
585+
log_w("getStreamPtr: not connected");
584586
return nullptr;
585587
}
586588

libraries/HTTPClient/src/HTTPClient.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <memory>
3131
#include <Arduino.h>
3232
#include <WiFiClient.h>
33+
#include <WiFiClientSecure.h>
3334

3435
#define HTTPCLIENT_DEFAULT_TCP_TIMEOUT (5000)
3536

libraries/WiFiClientSecure/src/WiFiClientSecure.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ size_t WiFiClientSecure::write(const uint8_t *buf, size_t size)
134134
}
135135
int res = send_ssl_data(sslclient, buf, size);
136136
if (res < 0) {
137-
138137
stop();
139138
res = 0;
140139
}
@@ -148,7 +147,6 @@ int WiFiClientSecure::read(uint8_t *buf, size_t size)
148147
}
149148
int res = get_ssl_receive(sslclient, buf, size);
150149
if (res < 0) {
151-
152150
stop();
153151
}
154152
return res;

libraries/WiFiClientSecure/src/WiFiClientSecure.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
class WiFiClientSecure : public WiFiClient
2929
{
3030
protected:
31-
bool _connected;
3231
sslclient_context *sslclient;
3332

3433
const char *_CA_cert;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy