A HTTP/HTTPS Client for the mbed networking/CyaSSL ssl library
Dependents: Anpi dropbox_access php_access_auth TwitterReader ... more
Fork of HTTPClient by
HTTP and HTTPS Client Class with wolfSSL, embedded SSL library.
The class was forked from http://mbed.org/users/donatien/code/HTTPClient/
It, now, accepts url both with "http://" and "https://".
Allocate caller thread with 16kbytes or larger stack for "https" requests.
Rest of the API stays compatible with HTTPClient.
For more about the library, see http://www.wolfssl.com. http://wolfssl.com/yaSSL/Docs.html.
Extended methods:
- HTTPResult basicAuth(const char* user, const char* password); /* set id/passwd for basic Authentication */
- void setHeader(char *header) ; /* set http headers */
- HTTPResult setSSLversion(int minorV) ; /* set SSL/TLS version. 0: SSL3, 1: TLS1.0, 2: TLS1.1, 3: TLS1.2 */
Diff: HTTPClient.cpp
- Revision:
- 14:2744e0c0e527
- Parent:
- 13:be61104f4e91
- Child:
- 15:5ad07f90e895
--- a/HTTPClient.cpp Sun Aug 05 16:12:10 2012 +0000 +++ b/HTTPClient.cpp Tue Aug 28 15:55:32 2012 +0000 @@ -355,34 +355,44 @@ if( recvChunked ) { //Read chunk header - crlfPos=0; - for(crlfPos++; crlfPos < trfLen - 2; crlfPos++) + bool foundCrlf; + do { - if( buf[crlfPos] == '\r' && buf[crlfPos + 1] == '\n' ) - { - break; - } - } - if(crlfPos >= trfLen - 2) //Try to read more - { - if( trfLen < CHUNK_SIZE ) + foundCrlf = false; + crlfPos=0; + buf[trfLen]=0; + if(trfLen >= 2) { - size_t newTrfLen; - ret = recv(buf + trfLen, 0, CHUNK_SIZE - trfLen - 1, &newTrfLen); - trfLen += newTrfLen; - CHECK_CONN_ERR(ret); - continue; + for(; crlfPos < trfLen - 2; crlfPos++) + { + if( buf[crlfPos] == '\r' && buf[crlfPos + 1] == '\n' ) + { + foundCrlf = true; + break; + } + } } - else + if(!foundCrlf) //Try to read more { - PRTCL_ERR(); + if( trfLen < CHUNK_SIZE ) + { + size_t newTrfLen; + ret = recv(buf + trfLen, 0, CHUNK_SIZE - trfLen - 1, &newTrfLen); + trfLen += newTrfLen; + CHECK_CONN_ERR(ret); + continue; + } + else + { + PRTCL_ERR(); + } } - } + } while(!foundCrlf); buf[crlfPos] = '\0'; int n = sscanf(buf, "%x", &readLen); if(n!=1) { - ERR("Could not read chunk length"); + ERR("Could not read chunk length -- crlfpos == %d & got %s", crlfPos, buf); PRTCL_ERR(); } @@ -429,7 +439,7 @@ { size_t newTrfLen; //Read missing chars to find end of chunk - ret = recv(buf, 2 - trfLen, CHUNK_SIZE, &newTrfLen); + ret = recv(buf + trfLen, 2 - trfLen, CHUNK_SIZE - trfLen - 1, &newTrfLen); CHECK_CONN_ERR(ret); trfLen += newTrfLen; }