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 25:76084defa790, committed 2014-03-23
- Comitter:
- WiredHome
- Date:
- Sun Mar 23 20:40:05 2014 +0000
- Parent:
- 24:eee214e3e806
- Child:
- 26:58b6fe9f596b
- Commit message:
- Corrected a defect where the count of custom headers was not initialized. This caused it to try to send <random> number of headers.; Also, enabled HTTPFile.
Changed in this revision
--- a/HTTPClient.cpp Sat Mar 15 22:18:30 2014 +0000 +++ b/HTTPClient.cpp Sun Mar 23 20:40:05 2014 +0000 @@ -46,7 +46,8 @@ #include "HTTPClient.h" HTTPClient::HTTPClient() : - m_sock(), m_basicAuthUser(NULL), m_basicAuthPassword(NULL), m_httpResponseCode(0), + m_sock(), m_basicAuthUser(NULL), m_basicAuthPassword(NULL), + m_nCustomHeaders(0), m_httpResponseCode(0), m_maxredirections(1), m_location(NULL) { @@ -200,6 +201,7 @@ } // send authorization + INFO("send auth (if defined)"); if (m_basicAuthUser && m_basicAuthPassword) { strcpy(buf, "Authorization: Basic "); createauth(m_basicAuthUser, m_basicAuthPassword, buf+strlen(buf), sizeof(buf)-strlen(buf)); @@ -215,6 +217,7 @@ } //Send all headers + INFO("Send custom header(s) %d (if any)", m_nCustomHeaders); for (size_t nh = 0; nh < m_nCustomHeaders * 2; nh+=2) { INFO("hdr[%d] %s:", nh, m_customHeaders[nh]); INFO(" %s", m_customHeaders[nh+1]); @@ -293,7 +296,8 @@ //Receive response DBG("Receiving response"); - ret = recv(buf, CHUNK_SIZE - 1, CHUNK_SIZE - 1, &trfLen); //Read n bytes + //ret = recv(buf, CHUNK_SIZE - 1, CHUNK_SIZE - 1, &trfLen); //Read n bytes + ret = recv(buf, 1, CHUNK_SIZE - 1, &trfLen); // recommended by Rob Noble to avoid timeout wait CHECK_CONN_ERR(ret); buf[trfLen] = '\0'; INFO("Received \r\n(%s\r\n)", buf); @@ -362,7 +366,7 @@ int n = sscanf(buf, "%31[^:]: %63[^\r\n]", key, value); if ( n == 2 ) { - DBG("Read header : %s: %s\n", key, value); + DBG("Read header : %s: %s", key, value); if( !strcmp(key, "Content-Length") ) { sscanf(value, "%d", &recvContentLength); pDataIn->setDataLen(recvContentLength);
--- a/data/HTTPFile.cpp Sat Mar 15 22:18:30 2014 +0000 +++ b/data/HTTPFile.cpp Sun Mar 23 20:40:05 2014 +0000 @@ -1,5 +1,5 @@ #include "HTTPFile.h" -#if 0 +#if 1 HTTPFile::HTTPFile(char* filename) { file = fopen(filename, "w"); } @@ -30,9 +30,9 @@ } -void HTTPFile::setLocation(const char * location) { - -} +//void HTTPFile::setLocation(const char * location) { +// +//} void HTTPFile::setIsChunked(bool chunked) { m_chunked = chunked;
--- a/data/HTTPFile.h Sat Mar 15 22:18:30 2014 +0000 +++ b/data/HTTPFile.h Sun Mar 23 20:40:05 2014 +0000 @@ -1,6 +1,6 @@ #ifndef HTTPFILE_H #define HTTPFILE_H -#if 0 +#if 1 #include <mbed.h> #include "../IHTTPData.h" @@ -49,4 +49,4 @@ bool m_chunked; }; #endif -#endif \ No newline at end of file +#endif // HTTPFILE_H \ No newline at end of file