Add HTTP GET function

The function performs a HTTP GET on a URL and returns the HTTP response.
This commit is contained in:
Markus Mäkelä
2018-08-19 07:05:22 +03:00
parent 91ab59530f
commit f8fb9510c9
6 changed files with 111 additions and 3 deletions

View File

@ -22,12 +22,14 @@
#include <array>
#include <functional>
#include <iterator>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include <maxscale/buffer.h>
#include <maxscale/utils.h>
#include <maxscale/jansson.hh>
namespace maxscale
{
@ -645,4 +647,26 @@ uint64_t get_byteN(const uint8_t* ptr, int bytes);
*/
uint8_t* set_byteN(uint8_t* ptr, uint64_t value, int bytes);
namespace http
{
struct Result
{
int code; // HTTP response code
std::string raw_body; // Raw response body
std::unique_ptr<json_t> body; // JSON form of the body if it was valid JSON
std::unordered_map<std::string, std::string> headers; // Headers attached to the response
};
/**
* Do a HTTP GET
*
* @param url URL to use
*
* @return A Result
*/
Result get(const std::string& url);
}
}