2019-02-14 19:14:57 +01:00
|
|
|
/*
|
|
|
|
* IXHttpClient.h
|
|
|
|
* Author: Benjamin Sergeant
|
|
|
|
* Copyright (c) 2019 Machine Zone, Inc. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <functional>
|
|
|
|
#include <mutex>
|
|
|
|
#include <atomic>
|
|
|
|
#include <tuple>
|
2019-02-15 05:11:42 +01:00
|
|
|
#include <memory>
|
2019-02-26 00:55:38 +01:00
|
|
|
#include <map>
|
2019-02-14 19:14:57 +01:00
|
|
|
|
|
|
|
#include "IXSocket.h"
|
|
|
|
#include "IXWebSocketHttpHeaders.h"
|
|
|
|
|
2019-02-26 00:55:38 +01:00
|
|
|
namespace ix
|
2019-02-14 19:14:57 +01:00
|
|
|
{
|
2019-02-15 05:11:42 +01:00
|
|
|
using HttpResponse = std::tuple<int, WebSocketHttpHeaders, std::string, std::string>;
|
2019-02-26 00:55:38 +01:00
|
|
|
using HttpParameters = std::map<std::string, std::string>;
|
2019-02-14 19:14:57 +01:00
|
|
|
|
2019-02-28 01:35:00 +01:00
|
|
|
struct HttpRequestArgs
|
|
|
|
{
|
|
|
|
std::string url;
|
|
|
|
WebSocketHttpHeaders extraHeaders;
|
|
|
|
std::string body;
|
|
|
|
int timeoutSecs;
|
|
|
|
bool followRedirects;
|
|
|
|
bool verbose;
|
|
|
|
};
|
|
|
|
|
2019-02-14 19:14:57 +01:00
|
|
|
class HttpClient {
|
|
|
|
public:
|
|
|
|
HttpClient();
|
|
|
|
~HttpClient();
|
|
|
|
|
2019-02-28 01:35:00 +01:00
|
|
|
HttpResponse get(HttpRequestArgs args);
|
|
|
|
HttpResponse head(HttpRequestArgs args);
|
2019-02-26 07:01:04 +01:00
|
|
|
|
2019-02-28 01:35:00 +01:00
|
|
|
HttpResponse post(const HttpParameters& httpParameters,
|
|
|
|
HttpRequestArgs args);
|
|
|
|
HttpResponse post(const std::string& body,
|
|
|
|
HttpRequestArgs args);
|
2019-02-14 19:14:57 +01:00
|
|
|
|
|
|
|
private:
|
2019-02-28 01:35:00 +01:00
|
|
|
HttpResponse request(const std::string& verb,
|
|
|
|
const std::string& body,
|
|
|
|
HttpRequestArgs args);
|
|
|
|
|
|
|
|
std::string serializeHttpParameters(const HttpParameters& httpParameters);
|
2019-02-26 00:55:38 +01:00
|
|
|
|
|
|
|
std::string urlEncode(const std::string& value);
|
|
|
|
|
2019-02-15 05:11:42 +01:00
|
|
|
std::shared_ptr<Socket> _socket;
|
2019-02-14 19:14:57 +01:00
|
|
|
};
|
|
|
|
}
|