@@ -45,23 +45,25 @@ class HttpRequest {
45
45
}
46
46
47
47
operator bool () {
48
- return (bool )*client_ptr;
48
+ return client_ptr != nullptr ? (bool )*client_ptr : false ;
49
49
}
50
50
51
51
virtual bool connected (){
52
- return client_ptr->connected ();
52
+ return client_ptr != nullptr ? ( bool )*client_ptr && client_ptr ->connected () : false ;
53
53
}
54
54
55
55
virtual int available () {
56
56
if (reply_header.isChunked ()){
57
57
return chunk_reader.available ();
58
58
}
59
- return client_ptr->available ();
59
+ return client_ptr != nullptr ? client_ptr ->available () : 0 ;
60
60
}
61
61
62
62
virtual void stop (){
63
63
LOGI (" stop" );
64
- client_ptr->stop ();
64
+ if (client_ptr!=nullptr ){
65
+ client_ptr->stop ();
66
+ }
65
67
}
66
68
67
69
virtual int post (Url &url, const char * mime, const char *data, int len=-1 ){
@@ -158,14 +160,19 @@ class HttpRequest {
158
160
159
161
// sends request and reads the reply_header from the server
160
162
virtual int process (MethodID action, Url &url, const char * mime, const char *data, int len=-1 ){
161
- if (!connected ()){
163
+ if (client_ptr==nullptr ){
164
+ LOGE (" The client has not been defined" );
165
+ return -1 ;
166
+ }
167
+ if (!this ->connected ()){
162
168
char msg[1024 ];
163
-
164
169
LOGI (" process connecting to host %s port %d" , url.host (), url.port ());
165
- bool connected = connect (url.host (), url.port ());
166
- if (!connected ){
170
+ bool is_connected = connect (url.host (), url.port ());
171
+ if (!is_connected ){
167
172
LOGE (" Connect failed" );
168
173
}
174
+ } else {
175
+ LOGI (" process is already connected" );
169
176
}
170
177
171
178
host_name = url.host ();
@@ -184,12 +191,13 @@ class HttpRequest {
184
191
request_header.write (*client_ptr);
185
192
186
193
if (len>0 ){
187
- LOGI (" process - writing data: %d bytes" , len);
194
+ LOGI (" Writing data: %d bytes" , len);
188
195
client_ptr->write ((const uint8_t *)data,len);
196
+ LOGD (data);
189
197
}
190
- client_ptr-> flush ();
198
+
191
199
LOGI (" Request written ... waiting for reply" )
192
-
200
+ client_ptr-> flush ();
193
201
reply_header.read (*client_ptr);
194
202
195
203
// if we use chunked tranfer we need to read the first chunked length
0 commit comments