From 99f056f230b86bed5885565d4ed84432e91e6ee7 Mon Sep 17 00:00:00 2001 From: Eric Knauel Date: Sun, 16 Oct 2016 13:13:49 +0200 Subject: [PATCH 1/3] add platformio library definition --- library.json | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 library.json diff --git a/library.json b/library.json new file mode 100644 index 0000000..68e5c2d --- /dev/null +++ b/library.json @@ -0,0 +1,13 @@ +{ + "name":"ArduinoHttpClientEk", + "version":"0.1", + "keywords":"http", + "description":"A fork of ArduinoHttpClient with simpler support for basic authentication (for POSR only).", + "repository":{ + "type":"git", + "url":"https://github.com/aehrisch/ArduinoHttpClient.git" + }, + "frameworks": ["arduino"], + "platforms": ["espressif8266"], + "homepage": null +} From 76d563079990fede30c5df010f62f3656da05e20 Mon Sep 17 00:00:00 2001 From: Eric Knauel Date: Sun, 16 Oct 2016 13:14:45 +0200 Subject: [PATCH 2/3] add method setRequestHeader --- src/HttpClient.cpp | 24 +++++++++++++++--------- src/HttpClient.h | 5 ++++- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/HttpClient.cpp b/src/HttpClient.cpp index 498d26c..f3f7a49 100644 --- a/src/HttpClient.cpp +++ b/src/HttpClient.cpp @@ -59,7 +59,7 @@ void HttpClient::beginRequest() iState = eRequestStarted; } -int HttpClient::startRequest(const char* aURLPath, const char* aHttpMethod, +int HttpClient::startRequest(const char* aURLPath, const char* aHttpMethod, const char* aContentType, int aContentLength, const byte aBody[]) { if (iState == eReadingBody) @@ -96,7 +96,7 @@ int HttpClient::startRequest(const char* aURLPath, const char* aHttpMethod, Serial.println("Connection failed"); #endif return HTTP_ERROR_CONNECTION_FAILED; - } + } } } else @@ -121,6 +121,10 @@ int HttpClient::startRequest(const char* aURLPath, const char* aHttpMethod, sendHeader(HTTP_HEADER_CONTENT_LENGTH, aContentLength); } + if (requestHeader) { + sendHeader(requestHeader); + } + bool hasBody = (aBody && aContentLength > 0); if (initialState == eIdle || hasBody) @@ -199,6 +203,11 @@ void HttpClient::sendHeader(const char* aHeaderName, const int aHeaderValue) iClient->println(aHeaderValue); } +void HttpClient::setRequestHeader(const String& header); +{ + requestHeader = header; +} + void HttpClient::sendBasicAuth(const char* aUser, const char* aPassword) { // Send the initial part of this header line @@ -382,7 +391,7 @@ int HttpClient::responseStatusCode() const char* statusPrefix = "HTTP/*.* "; const char* statusPtr = statusPrefix; // Whilst we haven't timed out & haven't reached the end of the headers - while ((c != '\n') && + while ((c != '\n') && ( (millis() - timeoutStart) < iHttpResponseTimeout )) { if (available()) @@ -475,7 +484,7 @@ int HttpClient::skipResponseHeaders() // Just keep reading until we finish reading the headers or time out unsigned long timeoutStart = millis(); // Whilst we haven't timed out & haven't reached the end of the headers - while ((!endOfHeadersReached()) && + while ((!endOfHeadersReached()) && ( (millis() - timeoutStart) < iHttpResponseTimeout )) { if (available()) @@ -505,7 +514,7 @@ int HttpClient::skipResponseHeaders() int HttpClient::contentLength() { - // skip the response headers, if they haven't been read already + // skip the response headers, if they haven't been read already if (!endOfHeadersReached()) { skipResponseHeaders(); @@ -573,7 +582,7 @@ bool HttpClient::headerAvailable() { // end of the line, all done break; - } + } else { // ignore any CR or LF characters @@ -710,6 +719,3 @@ int HttpClient::readHeader() // And return the character read to whoever wants it return c; } - - - diff --git a/src/HttpClient.h b/src/HttpClient.h index 141b2df..dc6785e 100644 --- a/src/HttpClient.h +++ b/src/HttpClient.h @@ -140,7 +140,7 @@ class HttpClient : public Client /** Send an additional header line. This can only be called in between the calls to startRequest and finishRequest. @param aHeader Header line to send, in its entirety (but without the - trailing CRLF. E.g. "Authorization: Basic YQDDCAIGES" + trailing CRLF. E.g. "Authorization: Basic YQDDCAIGES" */ void sendHeader(const char* aHeader); @@ -172,6 +172,8 @@ class HttpClient : public Client void sendHeader(const String& aHeaderName, const int aHeaderValue) { sendHeader(aHeaderName.c_str(), aHeaderValue); } + void setRequestHeader(cons String& header); + /** Send a basic authentication header. This will encode the given username and password, and send them in suitable header line for doing Basic Authentication. @@ -345,6 +347,7 @@ class HttpClient : public Client bool iConnectionClose; bool iSendDefaultRequestHeaders; String iHeaderLine; + String requestHeader; }; #endif From 6755ed2dff3afb76a60ed364d83924e6b4be3587 Mon Sep 17 00:00:00 2001 From: Eric Knauel Date: Sun, 16 Oct 2016 22:08:33 +0200 Subject: [PATCH 3/3] fix syntax error --- src/HttpClient.cpp | 2 +- src/HttpClient.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/HttpClient.cpp b/src/HttpClient.cpp index f3f7a49..003e490 100644 --- a/src/HttpClient.cpp +++ b/src/HttpClient.cpp @@ -203,7 +203,7 @@ void HttpClient::sendHeader(const char* aHeaderName, const int aHeaderValue) iClient->println(aHeaderValue); } -void HttpClient::setRequestHeader(const String& header); +void HttpClient::setRequestHeader(const String& header) { requestHeader = header; } diff --git a/src/HttpClient.h b/src/HttpClient.h index dc6785e..b211343 100644 --- a/src/HttpClient.h +++ b/src/HttpClient.h @@ -172,7 +172,7 @@ class HttpClient : public Client void sendHeader(const String& aHeaderName, const int aHeaderValue) { sendHeader(aHeaderName.c_str(), aHeaderValue); } - void setRequestHeader(cons String& header); + void setRequestHeader(const String& header); /** Send a basic authentication header. This will encode the given username and password, and send them in suitable header line for doing Basic