1
0
mirror of https://github.com/arduino-libraries/ArduinoHttpClient.git synced 2025-04-19 21:22:15 +03:00

Remove proxy support (for now)

This commit is contained in:
Sandeep Mistry 2016-06-17 10:13:56 -04:00
parent ad9bd94136
commit e3a6c20cd9
2 changed files with 7 additions and 87 deletions

View File

@ -4,36 +4,16 @@
#include "HttpClient.h" #include "HttpClient.h"
#include "b64.h" #include "b64.h"
#ifdef PROXY_ENABLED // currently disabled as introduces dependency on Dns.h in Ethernet
#include <Dns.h>
#endif
// Initialize constants // Initialize constants
const char* HttpClient::kUserAgent = "Arduino/2.2.0"; const char* HttpClient::kUserAgent = "Arduino/2.2.0";
const char* HttpClient::kContentLengthPrefix = HTTP_HEADER_CONTENT_LENGTH ": "; 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) HttpClient::HttpClient(Client& aClient)
: iClient(&aClient) : iClient(&aClient)
{ {
resetState(); resetState();
} }
#endif
void HttpClient::resetState() void HttpClient::resetState()
{ {
@ -64,27 +44,12 @@ int HttpClient::startRequest(const char* aServerName, uint16_t aServerPort, cons
return HTTP_ERROR_API; return HTTP_ERROR_API;
} }
#ifdef PROXY_ENABLED if (!iClient->connect(aServerName, aServerPort) > 0)
if (iProxyPort)
{ {
if (!iClient->connect(iProxyAddress, iProxyPort) > 0)
{
#ifdef LOGGING #ifdef LOGGING
Serial.println("Proxy connection failed"); Serial.println("Connection failed");
#endif #endif
return HTTP_ERROR_CONNECTION_FAILED; 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;
}
} }
// Now we're connected, send the first part of the request // 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; return HTTP_ERROR_API;
} }
#ifdef PROXY_ENABLED if (!iClient->connect(aServerAddress, aServerPort) > 0)
if (iProxyPort)
{ {
if (!iClient->connect(iProxyAddress, iProxyPort) > 0)
{
#ifdef LOGGING #ifdef LOGGING
Serial.println("Proxy connection failed"); Serial.println("Connection failed");
#endif #endif
return HTTP_ERROR_CONNECTION_FAILED; 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;
}
} }
// Now we're connected, send the first part of the request // 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" // Send the HTTP command, i.e. "GET /somepath/ HTTP/1.0"
iClient->print(aHttpMethod); iClient->print(aHttpMethod);
iClient->print(" "); 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->print(aURLPath);
iClient->println(" HTTP/1.1"); iClient->println(" HTTP/1.1");
// The host header, if required // The host header, if required

View File

@ -44,11 +44,7 @@ public:
// FIXME Write longer API request, using port and user-agent, example // FIXME Write longer API request, using port and user-agent, example
// FIXME Update tempToPachube example to calculate Content-Length correctly // 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); HttpClient(Client& aClient);
#endif
/** Start a more complex request. /** Start a more complex request.
Use this when you need to send additional headers in the request, Use this when you need to send additional headers in the request,
@ -440,11 +436,6 @@ protected:
int iBodyLengthConsumed; int iBodyLengthConsumed;
// How far through a Content-Length header prefix we are // How far through a Content-Length header prefix we are
const char* iContentLengthPtr; 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; uint32_t iHttpResponseTimeout;
}; };