1 #ifndef HAVE_HTTP_CLIENT_H
2 #define HAVE_HTTP_CLIENT_H 1
18 GET, POST, PUT, DELETE
26 friend size_t write_callback(
void *ptr,
size_t size,
size_t nmemm,
void *response);
27 friend size_t read_callback(
void *ptr,
size_t size,
size_t nmemb,
void *request);
36 Body() : ptr(NULL), length(0), managed(
false) {};
40 Body(
char* ptr,
size_t length,
const std::string& content_type) : ptr(ptr), length(length), type(content_type), managed(
false), pos(0) {};
41 Body(
const std::string& data,
const std::string& content_type);
45 const char* getContent()
const {
return ptr; };
62 friend std::ostream& operator<<(std::ostream& os,
const Message& req);
63 friend std::istream& operator>>(std::istream& is,
const Message& req);
65 typedef std::map<std::string,std::string> header_map;
77 Message() : body(NULL) { headers[
"Expect"]=
""; };
83 inline const std::string&
getHeader(
const std::string hdr)
const {
return headers.at(hdr); };
109 friend std::ostream& operator<<(std::ostream& os,
const Request& req);
110 friend std::istream& operator>>(std::istream& is,
const Request& req);
112 friend size_t read_callback(
void *ptr,
size_t size,
size_t nmemb,
void *request);
124 Request(Method type, std::string url) :
Message(), type(type), url(url) {};
134 inline const std::string&
getURL()
const {
return url; }
140 inline Request&
setHeader(
const std::string hdr,
const std::string value) { headers[hdr] = value;
return *
this; };
154 Request&
setBody(
char *ptr,
size_t length,
const std::string content_type);
162 Request&
setBody(
const std::string data,
const std::string content_type);
178 friend size_t header_callback(
char *buffer,
size_t size,
size_t nitems,
void *response);
179 friend size_t write_callback(
void *ptr,
size_t size,
size_t nmemm,
void *response);
190 long getStatus()
const {
return status; };
210 std::ostream& operator<<(std::ostream& os,
const Message& req);
211 std::ostream& operator<<(std::ostream& os,
const Request& req);
212 std::ostream& operator<<(std::ostream& os,
const Response& resp);
213 std::istream& operator>>(std::istream& is,
const Message& req);
214 std::istream& operator>>(std::istream& is,
const Request& req);
size_t getContentLength() const
Get the length of the content of this request.
Definition: http_client.hpp:50
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in c...
Definition: http_client.cpp:23
HTTPClient()
Initialise cURL HTTP client; carries out main cURL initialisation and registers callbacks.
Definition: http_client.cpp:172
const Body * getBody() const
Return the body of the message.
Definition: http_client.hpp:89
Request & setBody(char *ptr, size_t length, const std::string content_type)
Set the request body for the request, starting at the given memory location and counting length bytes...
Definition: http_client.hpp:177
const std::string & getContentType() const
Get the type of the content of this request.
Definition: http_client.hpp:55
Request & setHeader(const std::string hdr, const std::string value)
Add an HTTP header to the request.
Definition: http_client.hpp:140
curl_slist * getCurlHeaders()
Return the headers in CURL format.
Definition: http_client.cpp:50
Request & delHeader(const std::string hdr)
Remove an HTTP header from the request.
Definition: http_client.hpp:146
Definition: http_client.hpp:22
Request & setBody(Body &body)
Set the request body for the request, using the given body object.
Definition: http_client.hpp:169
A simple HTTP client.
Definition: http_client.hpp:198
Method getMethod() const
Return the request method.
Definition: http_client.hpp:129
void setCurlHeaders(curl_slist *hdr)
Set the headers in CURL format.
Definition: http_client.cpp:62
Definition: http_client.hpp:60
const std::string & getHeader(const std::string hdr) const
Return the header with the given name.
Definition: http_client.hpp:83
Definition: http_client.hpp:107
const std::string & getURL() const
Return the request URL.
Definition: http_client.hpp:134
~HTTPClient()
Clean up cURL HTTP client; carries out main cURL shutdown.
Definition: http_client.cpp:180