Fixed custom headers and Basic authorization, added support for redirection, functional file download interface can be used for SW updates and more.
Dependents: Sample_HTTPClient Sample_HTTPClient LWM2M_NanoService_Ethernet LWM2M_NanoService_Ethernet ... more
Fork of HTTPClient by
More recent changes - added iCal processing.
Derivative of a derivative, however this one works when it comes to supplying Basic authorization to access a protected resource. Some additional changes to the debug interface to clean it up for consistency with many other components I have.
Revision 43:12a6ae712bcd, committed 2017-07-20
- Comitter:
- WiredHome
- Date:
- Thu Jul 20 10:56:03 2017 +0000
- Parent:
- 42:ab259a9d1d36
- Child:
- 44:0e3b0849b2c7
- Commit message:
- Small memory reduction in ::FormatCTime(),; Minor tweaks to debug information.
Changed in this revision
HTTPClient.cpp | Show annotated file Show diff for this revision Revisions of this file |
data/HTTPiCal.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/HTTPClient.cpp Sun Jun 04 15:51:38 2017 +0000 +++ b/HTTPClient.cpp Thu Jul 20 10:56:03 2017 +0000 @@ -126,7 +126,7 @@ HTTPResult HTTPClient::get(const char* url, char* result, size_t maxResultLen, int timeout /*= HTTP_CLIENT_DEFAULT_TIMEOUT*/) //Blocking { - INFO("url: %s, timeout: %d", url, timeout); + INFO("url: %s, maxResultLen %d, timeout: %d", url, maxResultLen, timeout); HTTPText str(result, maxResultLen); return get(url, &str, timeout); } @@ -512,6 +512,7 @@ if(readLen) { ret = recv(buf, 1, CHUNK_SIZE - trfLen - 1, &trfLen); CHECK_CONN_ERR(ret); + INFO("recv'd next chunk ret: %d", ret); } } while(readLen); @@ -523,6 +524,7 @@ ret = recv(buf + trfLen, 2 - trfLen, CHUNK_SIZE - trfLen - 1, &newTrfLen); CHECK_CONN_ERR(ret); trfLen += newTrfLen; + INFO("recv'd next chunk ret: %d", ret); } if( (buf[0] != '\r') || (buf[1] != '\n') ) { ERR("Format error"); @@ -533,12 +535,9 @@ } else { break; } - } - m_sock.close(); DBG("Completed HTTP transaction"); - return HTTP_OK; } @@ -620,14 +619,14 @@ { char* schemePtr = (char*) url; char* hostPtr = (char*) strstr(url, "://"); - INFO("parseURL(%s,%s,%d,%s,%d,%d,%s,%d", + INFO("parseURL(%s,%p,%d,%s,%d,%d,%p,%d", url, scheme, maxSchemeLen, host, maxHostLen, *port, path, maxPathLen); - if(hostPtr == NULL) { + if (hostPtr == NULL) { WARN("Could not find host"); return HTTP_PARSE; //URL is invalid } - if( (uint16_t)maxSchemeLen < hostPtr - schemePtr + 1 ) { //including NULL-terminating char + if ( (uint16_t)maxSchemeLen < hostPtr - schemePtr + 1 ) { //including NULL-terminating char WARN("Scheme str is too small (%d >= %d)", maxSchemeLen, hostPtr - schemePtr + 1); return HTTP_PARSE; }
--- a/data/HTTPiCal.cpp Sun Jun 04 15:51:38 2017 +0000 +++ b/data/HTTPiCal.cpp Thu Jul 20 10:56:03 2017 +0000 @@ -192,12 +192,16 @@ return tStamp; } +// since this returns the string from a static buffer, and unknowing users +// might call this twice in a single command (e.g. printf(..., FormatCTime(time1), FormatCTime(time2)); +// this define controls how many of these can execute. +#define NumCallsPerArgList 2 char * HTTPiCal::FormatCTime(time_t t) { - static char temp[4][80]; + static char temp[NumCallsPerArgList][80]; static int i = 0; - i &= 3; + i %= NumCallsPerArgList; strcpy(temp[i], ctime(&t)); temp[i][strlen(temp[i])-1] = '\0'; return temp[i++];