Experimental HTTP and HTTPS library for mbed OS 5

Files at this revision

API Documentation at this revision

Comitter:
Jan Jongboom
Date:
Wed Jan 03 11:23:22 2018 +0000
Parent:
21:fcd2bfd31a39
Child:
23:15fa2726f793
Commit message:
Fix for https://github.com/ARMmbed/mbed-os/issues/5774

Changed in this revision

README.md Show annotated file Show diff for this revision Revisions of this file
source/http_request.h Show annotated file Show diff for this revision Revisions of this file
--- a/README.md	Thu Dec 14 16:19:22 2017 +0700
+++ b/README.md	Wed Jan 03 11:23:22 2018 +0000
@@ -61,8 +61,8 @@
     // do something with the data
 }
 
-HttpRequest* req = new HttpRequest(network, HTTP_GET, "http://pathtolargefile.com");
-req->send(NULL, 0, body_callback);
+HttpRequest* req = new HttpRequest(network, HTTP_GET, "http://pathtolargefile.com", &body_callback);
+req->send(NULL, 0);
 ```
 
 ## Socket re-use
--- a/source/http_request.h	Thu Dec 14 16:19:22 2017 +0700
+++ b/source/http_request.h	Wed Jan 03 11:23:22 2018 +0000
@@ -139,12 +139,27 @@
         size_t request_size = 0;
         char* request = request_builder->build(body, body_size, request_size);
 
-        nsapi_size_or_error_t send_result = socket->send(request, request_size);
+        nsapi_size_or_error_t total_send_count = 0;
+        while (total_send_count < request_size) {
+            nsapi_size_or_error_t send_result = socket->send(request + total_send_count, request_size - total_send_count);
+
+            if (send_result < 0) {
+                total_send_count = send_result;
+                break;
+            }
+
+            if (send_result == 0) {
+                break;
+            }
+
+            total_send_count += send_result;
+        }
+
 
         free(request);
 
-        if (send_result != request_size) {
-            error = send_result;
+        if (total_send_count < 0) {
+            error = total_send_count;
             return NULL;
         }