4
4
5
5
#include " HttpClient.h"
6
6
#include " b64.h"
7
- #ifdef PROXY_ENABLED // currently disabled as introduces dependency on Dns.h in Ethernet
8
- #include < Dns.h>
9
- #endif
10
7
11
8
// Initialize constants
12
9
const char * HttpClient::kUserAgent = " Arduino/2.2.0" ;
13
10
const char * HttpClient::kContentLengthPrefix = HTTP_HEADER_CONTENT_LENGTH " : " ;
14
11
15
- #ifdef PROXY_ENABLED // currently disabled as introduces dependency on Dns.h in Ethernet
16
- HttpClient::HttpClient (Client& aClient, const char * aProxy, uint16_t aProxyPort)
17
- : iClient(&aClient), iProxyPort(aProxyPort)
18
- {
19
- resetState ();
20
- if (aProxy)
21
- {
22
- // Resolve the IP address for the proxy
23
- DNSClient dns;
24
- dns.begin (Ethernet.dnsServerIP ());
25
- // Not ideal that we discard any errors here, but not a lot we can do in the ctor
26
- // and we'll get a connect error later anyway
27
- (void )dns.getHostByName (aProxy, iProxyAddress);
28
- }
29
- }
30
- #else
31
12
HttpClient::HttpClient (Client& aClient)
32
13
: iClient(&aClient)
33
14
{
34
15
resetState ();
35
16
}
36
- #endif
37
17
38
18
void HttpClient::resetState ()
39
19
{
@@ -64,27 +44,12 @@ int HttpClient::startRequest(const char* aServerName, uint16_t aServerPort, cons
64
44
return HTTP_ERROR_API;
65
45
}
66
46
67
- #ifdef PROXY_ENABLED
68
- if (iProxyPort)
69
- {
70
- if (!iClient->connect (iProxyAddress, iProxyPort) > 0 )
71
- {
72
- #ifdef LOGGING
73
- Serial.println (" Proxy connection failed" );
74
- #endif
75
- return HTTP_ERROR_CONNECTION_FAILED;
76
- }
77
- }
78
- else
79
- #endif
47
+ if (!iClient->connect (aServerName, aServerPort) > 0 )
80
48
{
81
- if (!iClient->connect (aServerName, aServerPort) > 0 )
82
- {
83
49
#ifdef LOGGING
84
- Serial.println (" Connection failed" );
50
+ Serial.println (" Connection failed" );
85
51
#endif
86
- return HTTP_ERROR_CONNECTION_FAILED;
87
- }
52
+ return HTTP_ERROR_CONNECTION_FAILED;
88
53
}
89
54
90
55
// Now we're connected, send the first part of the request
@@ -107,27 +72,12 @@ int HttpClient::startRequest(const IPAddress& aServerAddress, const char* aServe
107
72
return HTTP_ERROR_API;
108
73
}
109
74
110
- #ifdef PROXY_ENABLED
111
- if (iProxyPort)
75
+ if (!iClient->connect (aServerAddress, aServerPort) > 0 )
112
76
{
113
- if (!iClient->connect (iProxyAddress, iProxyPort) > 0 )
114
- {
115
77
#ifdef LOGGING
116
- Serial.println (" Proxy connection failed" );
78
+ Serial.println (" Connection failed" );
117
79
#endif
118
- return HTTP_ERROR_CONNECTION_FAILED;
119
- }
120
- }
121
- else
122
- #endif
123
- {
124
- if (!iClient->connect (aServerAddress, aServerPort) > 0 )
125
- {
126
- #ifdef LOGGING
127
- Serial.println (" Connection failed" );
128
- #endif
129
- return HTTP_ERROR_CONNECTION_FAILED;
130
- }
80
+ return HTTP_ERROR_CONNECTION_FAILED;
131
81
}
132
82
133
83
// Now we're connected, send the first part of the request
@@ -150,28 +100,7 @@ int HttpClient::sendInitialHeaders(const char* aServerName, IPAddress aServerIP,
150
100
// Send the HTTP command, i.e. "GET /somepath/ HTTP/1.0"
151
101
iClient->print (aHttpMethod);
152
102
iClient->print (" " );
153
- #ifdef PROXY_ENABLED
154
- if (iProxyPort)
155
- {
156
- // We're going through a proxy, send a full URL
157
- iClient->print (" http://" );
158
- if (aServerName)
159
- {
160
- // We've got a server name, so use it
161
- iClient->print (aServerName);
162
- }
163
- else
164
- {
165
- // We'll have to use the IP address
166
- iClient->print (aServerIP);
167
- }
168
- if (aPort != kHttpPort )
169
- {
170
- iClient->print (" :" );
171
- iClient->print (aPort);
172
- }
173
- }
174
- #endif
103
+
175
104
iClient->print (aURLPath);
176
105
iClient->println (" HTTP/1.1" );
177
106
// The host header, if required
0 commit comments