From e3a6c20cd99517bfbd0e1781998f2285425e20a1 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Fri, 17 Jun 2016 10:13:56 -0400 Subject: [PATCH] Remove proxy support (for now) --- HttpClient.cpp | 85 +++++--------------------------------------------- HttpClient.h | 9 ------ 2 files changed, 7 insertions(+), 87 deletions(-) diff --git a/HttpClient.cpp b/HttpClient.cpp index 6efc4ea..3e7c852 100644 --- a/HttpClient.cpp +++ b/HttpClient.cpp @@ -4,36 +4,16 @@ #include "HttpClient.h" #include "b64.h" -#ifdef PROXY_ENABLED // currently disabled as introduces dependency on Dns.h in Ethernet -#include -#endif // Initialize constants const char* HttpClient::kUserAgent = "Arduino/2.2.0"; const char* HttpClient::kContentLengthPrefix = HTTP_HEADER_CONTENT_LENGTH ": "; -#ifdef PROXY_ENABLED // currently disabled as introduces dependency on Dns.h in Ethernet -HttpClient::HttpClient(Client& aClient, const char* aProxy, uint16_t aProxyPort) - : iClient(&aClient), iProxyPort(aProxyPort) -{ - resetState(); - if (aProxy) - { - // Resolve the IP address for the proxy - DNSClient dns; - dns.begin(Ethernet.dnsServerIP()); - // Not ideal that we discard any errors here, but not a lot we can do in the ctor - // and we'll get a connect error later anyway - (void)dns.getHostByName(aProxy, iProxyAddress); - } -} -#else HttpClient::HttpClient(Client& aClient) : iClient(&aClient) { resetState(); } -#endif void HttpClient::resetState() { @@ -64,27 +44,12 @@ int HttpClient::startRequest(const char* aServerName, uint16_t aServerPort, cons return HTTP_ERROR_API; } -#ifdef PROXY_ENABLED - if (iProxyPort) + if (!iClient->connect(aServerName, aServerPort) > 0) { - if (!iClient->connect(iProxyAddress, iProxyPort) > 0) - { #ifdef LOGGING - Serial.println("Proxy connection failed"); + Serial.println("Connection failed"); #endif - return HTTP_ERROR_CONNECTION_FAILED; - } - } - else -#endif - { - if (!iClient->connect(aServerName, aServerPort) > 0) - { -#ifdef LOGGING - Serial.println("Connection failed"); -#endif - return HTTP_ERROR_CONNECTION_FAILED; - } + return HTTP_ERROR_CONNECTION_FAILED; } // Now we're connected, send the first part of the request @@ -107,27 +72,12 @@ int HttpClient::startRequest(const IPAddress& aServerAddress, const char* aServe return HTTP_ERROR_API; } -#ifdef PROXY_ENABLED - if (iProxyPort) + if (!iClient->connect(aServerAddress, aServerPort) > 0) { - if (!iClient->connect(iProxyAddress, iProxyPort) > 0) - { #ifdef LOGGING - Serial.println("Proxy connection failed"); + Serial.println("Connection failed"); #endif - return HTTP_ERROR_CONNECTION_FAILED; - } - } - else -#endif - { - if (!iClient->connect(aServerAddress, aServerPort) > 0) - { -#ifdef LOGGING - Serial.println("Connection failed"); -#endif - return HTTP_ERROR_CONNECTION_FAILED; - } + return HTTP_ERROR_CONNECTION_FAILED; } // Now we're connected, send the first part of the request @@ -150,28 +100,7 @@ int HttpClient::sendInitialHeaders(const char* aServerName, IPAddress aServerIP, // Send the HTTP command, i.e. "GET /somepath/ HTTP/1.0" iClient->print(aHttpMethod); iClient->print(" "); -#ifdef PROXY_ENABLED - if (iProxyPort) - { - // We're going through a proxy, send a full URL - iClient->print("http://"); - if (aServerName) - { - // We've got a server name, so use it - iClient->print(aServerName); - } - else - { - // We'll have to use the IP address - iClient->print(aServerIP); - } - if (aPort != kHttpPort) - { - iClient->print(":"); - iClient->print(aPort); - } - } -#endif + iClient->print(aURLPath); iClient->println(" HTTP/1.1"); // The host header, if required diff --git a/HttpClient.h b/HttpClient.h index ff00083..d4d980c 100644 --- a/HttpClient.h +++ b/HttpClient.h @@ -44,11 +44,7 @@ public: // FIXME Write longer API request, using port and user-agent, example // FIXME Update tempToPachube example to calculate Content-Length correctly -#ifdef PROXY_ENABLED // currently disabled as introduces dependency on Dns.h in Ethernet - HttpClient(Client& aClient, const char* aProxy =NULL, uint16_t aProxyPort =0); -#else HttpClient(Client& aClient); -#endif /** Start a more complex request. Use this when you need to send additional headers in the request, @@ -440,11 +436,6 @@ protected: int iBodyLengthConsumed; // How far through a Content-Length header prefix we are const char* iContentLengthPtr; -#ifdef PROXY_ENABLED - // Address of the proxy to use, if we're using one - IPAddress iProxyAddress; - uint16_t iProxyPort; -#endif uint32_t iHttpResponseTimeout; };