Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: GR-PEACH_Azure_Speech
Fork of HTTPClient-SSL by
Revision 50:7fbf8ef951f2, committed 2015-11-07
- Comitter:
- ksekimoto
- Date:
- Sat Nov 07 12:20:31 2015 +0000
- Parent:
- 49:240f3b4f2733
- Commit message:
- The first version
Changed in this revision
--- a/HTTPClient.cpp Thu Jun 25 13:55:25 2015 +0000
+++ b/HTTPClient.cpp Sat Nov 07 12:20:31 2015 +0000
@@ -18,8 +18,8 @@
*/
// DMA: Added tunable to adapt size of larger input URLs
-#define MAX_URL_HOSTNAME_LENGTH 128
-#define MAX_URL_PATH_LENGTH 128
+#define MAX_URL_HOSTNAME_LENGTH 512
+#define MAX_URL_PATH_LENGTH 512
//Debug is disabled by default
#if 0
@@ -45,6 +45,8 @@
#define MIN(x,y) (((x)<(y))?(x):(y))
#define MAX(x,y) (((x)>(y))?(x):(y))
+#include "mbed.h"
+#include <string>
#include <cstring>
#include <settings.h>
@@ -55,8 +57,10 @@
#include "HTTPClient.h"
static TCPSocketConnection* m_sock;
-#define CHUNK_SIZE 256
-#define SEND_BUF_SIZE 1024
+//#define CHUNK_SIZE 256
+//#define SEND_BUF_SIZE 1024
+#define CHUNK_SIZE (1024*8)
+#define SEND_BUF_SIZE (1024*4)
static char send_buf[SEND_BUF_SIZE] ;
static char *send_buf_p = NULL;
@@ -425,6 +429,7 @@
return HTTP_CONN;
}
+ wait(0.3) ;
//Send all headers
//Send default headers
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/data/HTTPFile.cpp Sat Nov 07 12:20:31 2015 +0000
@@ -0,0 +1,41 @@
+#include "HTTPFile.h"
+
+HTTPFile::HTTPFile(char* filename) {
+ file = fopen(filename, "w");
+ //printf("HTTPFile open:%s\r\n", filename);
+}
+
+void HTTPFile::close() {
+ if (file) {
+ //printf("HTTPFile close\r\n");
+ fclose(file);
+ }
+}
+
+void HTTPFile::writeReset() {
+ if (file) {
+ rewind(file);
+ }
+}
+
+int HTTPFile::write(const char* buf, size_t len) {
+ if (file) {
+ len = fwrite(buf, 1, len, file);
+ if ((!m_chunked && (ftell(file) >= m_len)) || (m_chunked && !len)) {
+ close();
+ }
+ }
+ return len;
+}
+
+void HTTPFile::setDataType(const char* type) {
+
+}
+
+void HTTPFile::setIsChunked(bool chunked) {
+ m_chunked = chunked;
+}
+
+void HTTPFile::setDataLen(size_t len) {
+ m_len = len;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/data/HTTPFile.h Sat Nov 07 12:20:31 2015 +0000
@@ -0,0 +1,50 @@
+#ifndef HTTPFILE_H
+#define HTTPFILE_H
+
+#include <mbed.h>
+#include "../IHTTPData.h"
+
+class HTTPFile : public IHTTPDataIn {
+
+ public:
+ HTTPFile(char* filename);
+
+ /** Closes the file, should be called once the http connection is closed.
+ */
+ void close();
+
+ protected:
+
+ friend class HTTPClient;
+
+ /** Reset stream to its beginning
+ * Called by the HTTPClient on each new request
+ */
+ virtual void writeReset();
+
+ /** Write a piece of data transmitted by the server
+ * @param buf Pointer to the buffer from which to copy the data
+ * @param len Length of the buffer
+ */
+ virtual int write(const char* buf, size_t len);
+
+ /** Set MIME type
+ * @param type Internet media type from Content-Type header
+ */
+ virtual void setDataType(const char* type);
+
+ /** Determine whether the data is chunked
+ * Recovered from Transfer-Encoding header
+ */
+ virtual void setIsChunked(bool chunked);
+
+ /** If the data is not chunked, set its size
+ * From Content-Length header
+ */
+ virtual void setDataLen(size_t len);
+ private:
+ FILE *file;
+ size_t m_len;
+ bool m_chunked;
+};
+#endif
\ No newline at end of file
--- a/data/HTTPText.cpp Thu Jun 25 13:55:25 2015 +0000
+++ b/data/HTTPText.cpp Sat Nov 07 12:20:31 2015 +0000
@@ -17,6 +17,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+#include "mbed.h"
#include "HTTPText.h"
#include <cstring>
@@ -36,7 +37,7 @@
HTTPText::HTTPText(char* str, size_t size) : m_str(str), m_size(size), m_pos(0)
{
-
+ strcpy(m_datatype, "plan/text");
}
//IHTTPDataIn
@@ -55,7 +56,8 @@
/*virtual*/ int HTTPText::getDataType(char* type, size_t maxTypeLen) //Internet media type for Content-Type header
{
- strncpy(type, "plain/text", maxTypeLen-1);
+ //strncpy(type, "plain/text", maxTypeLen-1);
+ strncpy(type, m_datatype, maxTypeLen-1);
type[maxTypeLen-1] = '\0';
return OK;
}
@@ -87,7 +89,7 @@
/*virtual*/ void HTTPText::setDataType(const char* type) //Internet media type from Content-Type header
{
-
+ strcpy(m_datatype, type);
}
/*virtual*/ void HTTPText::setIsChunked(bool chunked) //From Transfer-Encoding header
--- a/data/HTTPText.h Thu Jun 25 13:55:25 2015 +0000
+++ b/data/HTTPText.h Sat Nov 07 12:20:31 2015 +0000
@@ -39,6 +39,8 @@
*/
HTTPText(char* str, size_t size);
+ void setDataType(const char* type); //Internet media type from Content-Type header
+
protected:
//IHTTPDataIn
virtual void readReset();
@@ -56,7 +58,7 @@
virtual int write(const char* buf, size_t len);
- virtual void setDataType(const char* type); //Internet media type from Content-Type header
+ //virtual void setDataType(const char* type); //Internet media type from Content-Type header
virtual void setIsChunked(bool chunked); //From Transfer-Encoding header
@@ -67,6 +69,8 @@
size_t m_size;
size_t m_pos;
+
+ char m_datatype[50];
};
#endif /* HTTPTEXT_H_ */
