@@ -23,16 +23,23 @@ static const int HTTP_ERROR_TIMED_OUT =-3;
23
23
// server?
24
24
static const int HTTP_ERROR_INVALID_RESPONSE =-4 ;
25
25
26
+ // Define some of the common methods and headers here
27
+ // That lets other code reuse them without having to declare another copy
28
+ // of them, so saves code space and RAM
29
+ #define HTTP_METHOD_GET " GET"
30
+ #define HTTP_METHOD_POST " POST"
31
+ #define HTTP_METHOD_PUT " PUT"
32
+ #define HTTP_METHOD_DELETE " DELETE"
33
+ #define HTTP_HEADER_CONTENT_LENGTH " Content-Length"
34
+ #define HTTP_HEADER_CONNECTION " Connection"
35
+ #define HTTP_HEADER_USER_AGENT " User-Agent"
36
+
26
37
class HttpClient : public Client
27
38
{
28
39
public:
29
40
static const int kNoContentLengthHeader =-1 ;
30
41
static const int kHttpPort =80 ;
31
42
static const char * kUserAgent ;
32
- static const char * kGet ;
33
- static const char * kPost ;
34
- static const char * kPut ;
35
- static const char * kDelete ;
36
43
37
44
// FIXME Write longer API request, using port and user-agent, example
38
45
// FIXME Update tempToPachube example to calculate Content-Length correctly
@@ -66,7 +73,7 @@ class HttpClient : public Client
66
73
*/
67
74
int get (const char * aServerName, uint16_t aServerPort, const char * aURLPath,
68
75
const char * aUserAgent =NULL )
69
- { return startRequest (aServerName, aServerPort, aURLPath, kGet , aUserAgent); }
76
+ { return startRequest (aServerName, aServerPort, aURLPath, HTTP_METHOD_GET , aUserAgent); }
70
77
71
78
/* * Connect to the server and start to send a GET request.
72
79
@param aServerName Name of the server being connected to. If NULL, the
@@ -77,7 +84,7 @@ class HttpClient : public Client
77
84
@return 0 if successful, else error
78
85
*/
79
86
int get (const char * aServerName, const char * aURLPath, const char * aUserAgent =NULL )
80
- { return startRequest (aServerName, kHttpPort , aURLPath, kGet , aUserAgent); }
87
+ { return startRequest (aServerName, kHttpPort , aURLPath, HTTP_METHOD_GET , aUserAgent); }
81
88
82
89
/* * Connect to the server and start to send a GET request. This version connects
83
90
doesn't perform a DNS lookup and just connects to the given IP address.
@@ -95,7 +102,7 @@ class HttpClient : public Client
95
102
uint16_t aServerPort,
96
103
const char * aURLPath,
97
104
const char * aUserAgent =NULL )
98
- { return startRequest (aServerAddress, aServerName, aServerPort, aURLPath, kGet , aUserAgent); }
105
+ { return startRequest (aServerAddress, aServerName, aServerPort, aURLPath, HTTP_METHOD_GET , aUserAgent); }
99
106
100
107
/* * Connect to the server and start to send a GET request. This version connects
101
108
doesn't perform a DNS lookup and just connects to the given IP address.
@@ -111,7 +118,7 @@ class HttpClient : public Client
111
118
const char * aServerName,
112
119
const char * aURLPath,
113
120
const char * aUserAgent =NULL )
114
- { return startRequest (aServerAddress, aServerName, kHttpPort , aURLPath, kGet , aUserAgent); }
121
+ { return startRequest (aServerAddress, aServerName, kHttpPort , aURLPath, HTTP_METHOD_GET , aUserAgent); }
115
122
116
123
/* * Connect to the server and start to send a POST request.
117
124
@param aServerName Name of the server being connected to. If NULL, the
@@ -126,7 +133,7 @@ class HttpClient : public Client
126
133
uint16_t aServerPort,
127
134
const char * aURLPath,
128
135
const char * aUserAgent =NULL )
129
- { return startRequest (aServerName, aServerPort, aURLPath, kPost , aUserAgent); }
136
+ { return startRequest (aServerName, aServerPort, aURLPath, HTTP_METHOD_POST , aUserAgent); }
130
137
131
138
/* * Connect to the server and start to send a POST request.
132
139
@param aServerName Name of the server being connected to. If NULL, the
@@ -139,7 +146,7 @@ class HttpClient : public Client
139
146
int post (const char * aServerName,
140
147
const char * aURLPath,
141
148
const char * aUserAgent =NULL )
142
- { return startRequest (aServerName, kHttpPort , aURLPath, kPost , aUserAgent); }
149
+ { return startRequest (aServerName, kHttpPort , aURLPath, HTTP_METHOD_POST , aUserAgent); }
143
150
144
151
/* * Connect to the server and start to send a POST request. This version connects
145
152
doesn't perform a DNS lookup and just connects to the given IP address.
@@ -157,7 +164,7 @@ class HttpClient : public Client
157
164
uint16_t aServerPort,
158
165
const char * aURLPath,
159
166
const char * aUserAgent =NULL )
160
- { return startRequest (aServerAddress, aServerName, aServerPort, aURLPath, kPost , aUserAgent); }
167
+ { return startRequest (aServerAddress, aServerName, aServerPort, aURLPath, HTTP_METHOD_POST , aUserAgent); }
161
168
162
169
/* * Connect to the server and start to send a POST request. This version connects
163
170
doesn't perform a DNS lookup and just connects to the given IP address.
@@ -173,7 +180,7 @@ class HttpClient : public Client
173
180
const char * aServerName,
174
181
const char * aURLPath,
175
182
const char * aUserAgent =NULL )
176
- { return startRequest (aServerAddress, aServerName, kHttpPort , aURLPath, kPost , aUserAgent); }
183
+ { return startRequest (aServerAddress, aServerName, kHttpPort , aURLPath, HTTP_METHOD_POST , aUserAgent); }
177
184
178
185
/* * Connect to the server and start to send a PUT request.
179
186
@param aServerName Name of the server being connected to. If NULL, the
@@ -188,7 +195,7 @@ class HttpClient : public Client
188
195
uint16_t aServerPort,
189
196
const char * aURLPath,
190
197
const char * aUserAgent =NULL )
191
- { return startRequest (aServerName, aServerPort, aURLPath, kPut , aUserAgent); }
198
+ { return startRequest (aServerName, aServerPort, aURLPath, HTTP_METHOD_PUT , aUserAgent); }
192
199
193
200
/* * Connect to the server and start to send a PUT request.
194
201
@param aServerName Name of the server being connected to. If NULL, the
@@ -201,7 +208,7 @@ class HttpClient : public Client
201
208
int put (const char * aServerName,
202
209
const char * aURLPath,
203
210
const char * aUserAgent =NULL )
204
- { return startRequest (aServerName, kHttpPort , aURLPath, kPut , aUserAgent); }
211
+ { return startRequest (aServerName, kHttpPort , aURLPath, HTTP_METHOD_PUT , aUserAgent); }
205
212
206
213
/* * Connect to the server and start to send a PUT request. This version connects
207
214
doesn't perform a DNS lookup and just connects to the given IP address.
@@ -219,7 +226,7 @@ class HttpClient : public Client
219
226
uint16_t aServerPort,
220
227
const char * aURLPath,
221
228
const char * aUserAgent =NULL )
222
- { return startRequest (aServerAddress, aServerName, aServerPort, aURLPath, kPut , aUserAgent); }
229
+ { return startRequest (aServerAddress, aServerName, aServerPort, aURLPath, HTTP_METHOD_PUT , aUserAgent); }
223
230
224
231
/* * Connect to the server and start to send a PUT request. This version connects
225
232
doesn't perform a DNS lookup and just connects to the given IP address.
@@ -235,7 +242,7 @@ class HttpClient : public Client
235
242
const char * aServerName,
236
243
const char * aURLPath,
237
244
const char * aUserAgent =NULL )
238
- { return startRequest (aServerAddress, aServerName, kHttpPort , aURLPath, kPut , aUserAgent); }
245
+ { return startRequest (aServerAddress, aServerName, kHttpPort , aURLPath, HTTP_METHOD_PUT , aUserAgent); }
239
246
240
247
/* * Connect to the server and start to send the request.
241
248
@param aServerName Name of the server being connected to.
0 commit comments