MCPcopy Create free account
hub / github.com/amcewen/HttpClient / HttpClient

Class HttpClient

HttpClient.h:37–447  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35#define HTTP_HEADER_USER_AGENT "User-Agent"
36
37class HttpClient : public Client
38{
39public:
40 static const int kNoContentLengthHeader =-1;
41 static const int kHttpPort =80;
42 static const char* kUserAgent;
43
44// FIXME Write longer API request, using port and user-agent, example
45// FIXME Update tempToPachube example to calculate Content-Length correctly
46
47#ifdef PROXY_ENABLED // currently disabled as introduces dependency on Dns.h in Ethernet
48 HttpClient(Client& aClient, const char* aProxy =NULL, uint16_t aProxyPort =0);
49#else
50 HttpClient(Client& aClient);
51#endif
52
53 /** Start a more complex request.
54 Use this when you need to send additional headers in the request,
55 but you will also need to call endRequest() when you are finished.
56 */
57 void beginRequest();
58
59 /** End a more complex request.
60 Use this when you need to have sent additional headers in the request,
61 but you will also need to call beginRequest() at the start.
62 */
63 void endRequest();
64
65 /** Connect to the server and start to send a GET request.
66 @param aServerName Name of the server being connected to. If NULL, the
67 "Host" header line won't be sent
68 @param aServerPort Port to connect to on the server
69 @param aURLPath Url to request
70 @param aUserAgent User-Agent string to send. If NULL the default
71 user-agent kUserAgent will be sent
72 @return 0 if successful, else error
73 */
74 int get(const char* aServerName, uint16_t aServerPort, const char* aURLPath,
75 const char* aUserAgent =NULL)
76 { return startRequest(aServerName, aServerPort, aURLPath, HTTP_METHOD_GET, aUserAgent); }
77
78 /** Connect to the server and start to send a GET request.
79 @param aServerName Name of the server being connected to. If NULL, the
80 "Host" header line won't be sent
81 @param aURLPath Url to request
82 @param aUserAgent User-Agent string to send. If NULL the default
83 user-agent kUserAgent will be sent
84 @return 0 if successful, else error
85 */
86 int get(const char* aServerName, const char* aURLPath, const char* aUserAgent =NULL)
87 { return startRequest(aServerName, kHttpPort, aURLPath, HTTP_METHOD_GET, aUserAgent); }
88
89 /** Connect to the server and start to send a GET request. This version connects
90 doesn't perform a DNS lookup and just connects to the given IP address.
91 @param aServerAddress IP address of the server to connect to
92 @param aServerName Name of the server being connected to. If NULL, the
93 "Host" header line won't be sent
94 @param aServerPort Port to connect to on the server

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected