--- tl.orig/nanohttp/nanohttp-socket.c
+++ tl/nanohttp/nanohttp-socket.c
@@ -501,27 +501,69 @@
 /* log_verbose3("Entering hsocket_read(total=%d,force=%d)", total, force); */
 
   totalRead = 0;
+  if(sock->buf_used)
+  {
+    if(total <= sock->buf_used)
+    {
+      memcpy(buffer, &sock->read_buf[sock->buf_start], total);
+      sock->buf_start += total;
+      sock->buf_used -= total;
+      *received = total;
+      return H_OK;
+    }
+    totalRead = sock->buf_used;
+    memcpy(buffer, &sock->read_buf[sock->buf_start], totalRead);
+    sock->buf_used = 0;
+  }
+
   do
   {
 
-    if ((status =
+    if(total - totalRead < sizeof(sock->read_buf))
+    {
+      if ((status =
+         hssl_read(sock, sock->read_buf,
+               sizeof(sock->read_buf), &count)) != H_OK)
+      {
+        log_warn2("hssl_read failed (%s)", herror_message(status));
+        return status;
+      }
+      if(count >= total - totalRead)
+      {
+        memcpy(&buffer[totalRead], sock->read_buf, total - totalRead);
+        *received = total;
+        sock->buf_used = count - total - totalRead;
+        sock->buf_start = total - totalRead;
+        return H_OK;
+      }
+      else
+      {
+        memcpy(&buffer[totalRead], sock->read_buf, count);
+        sock->buf_used = 0;
+        /* 10 lines below we do totalRead += count; */
+      }
+    }
+    else
+    {
+      if ((status =
          hssl_read(sock, &buffer[totalRead], (size_t) total - totalRead,
                    &count)) != H_OK)
-    {
-      log_warn2("hssl_read failed (%s)", herror_message(status));
-      return status;
+      {
+        log_warn2("hssl_read failed (%s)", herror_message(status));
+        return status;
+      }
     }
 
+    totalRead += count;
+
     if (!force)
     {
       /* log_verbose3("Leaving !force (received=%d)(status=%d)", *received,
          status); */
-      *received = count;
+      *received = totalRead;
       return H_OK;
     }
 
-    totalRead += count;
-
     if (totalRead == total)
     {
       *received = totalRead;
--- tl.orig/nanohttp/nanohttp-socket.h
+++ tl/nanohttp/nanohttp-socket.h
@@ -55,6 +55,8 @@
 #endif
   struct sockaddr_in addr;
   void *ssl;
+  char read_buf[2048];
+  int buf_start, buf_used;
 }
 hsocket_t;                      /* end of socket definition */
 
