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
|
|
|
|
|
|
|
class HttpClient {
|
|
|
|
public:
|
|
|
|
HttpClient();
|
|
|
|
~HttpClient();
|
|
|
|
|
|
|
|
// Static methods ?
|
2019-02-26 02:17:05 +01:00
|
|
|
HttpResponse get(const std::string& url,
|
|
|
|
const WebSocketHttpHeaders& extraHeaders,
|
2019-02-26 07:01:04 +01:00
|
|
|
bool followRedirects,
|
2019-02-26 02:17:05 +01:00
|
|
|
bool verbose);
|
2019-02-26 07:01:04 +01:00
|
|
|
|
2019-02-26 00:55:38 +01:00
|
|
|
HttpResponse post(const std::string& url,
|
2019-02-26 02:17:05 +01:00
|
|
|
const WebSocketHttpHeaders& extraHeaders,
|
2019-02-26 00:55:38 +01:00
|
|
|
const HttpParameters& httpParameters,
|
2019-02-26 07:01:04 +01:00
|
|
|
bool followRedirects,
|
|
|
|
bool verbose);
|
|
|
|
|
|
|
|
HttpResponse head(const std::string& url,
|
|
|
|
const WebSocketHttpHeaders& extraHeaders,
|
|
|
|
bool followRedirects,
|
2019-02-26 00:55:38 +01:00
|
|
|
bool verbose);
|
2019-02-14 19:14:57 +01:00
|
|
|
|
|
|
|
private:
|
2019-02-26 00:55:38 +01:00
|
|
|
HttpResponse request(const std::string& url,
|
|
|
|
const std::string& verb,
|
2019-02-26 02:17:05 +01:00
|
|
|
const WebSocketHttpHeaders& extraHeaders,
|
2019-02-26 00:55:38 +01:00
|
|
|
const HttpParameters& httpParameters,
|
2019-02-26 07:01:04 +01:00
|
|
|
bool followRedirects,
|
2019-02-26 00:55:38 +01:00
|
|
|
bool verbose);
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
}
|