-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,723 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) 2013-2019 mogemimi. Distributed under the MIT license. | ||
|
||
#pragma once | ||
|
||
#include "Pomdog/Basic/Export.hpp" | ||
#include "Pomdog/Network/detail/ForwardDeclarations.hpp" | ||
#include "Pomdog/Signals/detail/ForwardDeclarations.hpp" | ||
#include "Pomdog/Utility/Errors.hpp" | ||
#include <functional> | ||
#include <memory> | ||
#include <string> | ||
#include <tuple> | ||
|
||
namespace Pomdog { | ||
|
||
class POMDOG_EXPORT HTTPClient final { | ||
public: | ||
explicit HTTPClient(IOService* service); | ||
|
||
HTTPClient(const HTTPClient&) = delete; | ||
HTTPClient& operator=(const HTTPClient&) = delete; | ||
|
||
~HTTPClient(); | ||
|
||
/// Sends an HTTP request and returns an HTTP response. | ||
[[nodiscard]] std::shared_ptr<Error> | ||
Do(const std::shared_ptr<HTTPRequest>& req); | ||
|
||
/// Sends a GET request to the specified URL. | ||
[[nodiscard]] std::tuple<Connection, std::shared_ptr<Error>> | ||
Get(const std::string& url, | ||
std::function<void(std::unique_ptr<HTTPResponse>&&, const std::shared_ptr<Error>&)>&& callback); | ||
|
||
/// Sends a POST request to the specified URL. | ||
[[nodiscard]] std::tuple<Connection, std::shared_ptr<Error>> | ||
Post(const std::string& url, | ||
const std::string& contentType, | ||
std::vector<char>&& body, | ||
std::function<void(std::unique_ptr<HTTPResponse>&&, const std::shared_ptr<Error>&)>&& callback); | ||
|
||
/// Aborts the specified request immediately. | ||
[[nodiscard]] std::shared_ptr<Error> | ||
CancelRequest(const std::shared_ptr<HTTPRequest>& req); | ||
|
||
private: | ||
struct Impl; | ||
std::unique_ptr<Impl> impl; | ||
}; | ||
|
||
} // namespace Pomdog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) 2013-2019 mogemimi. Distributed under the MIT license. | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
|
||
namespace Pomdog { | ||
|
||
enum class HTTPMethod : std::int8_t { | ||
Get, | ||
Head, | ||
Post, | ||
Put, | ||
Delete, | ||
Connect, | ||
Trace, | ||
}; | ||
|
||
} // namespace Pomdog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) 2013-2019 mogemimi. Distributed under the MIT license. | ||
|
||
#pragma once | ||
|
||
#include "Pomdog/Basic/Export.hpp" | ||
#include "Pomdog/Network/detail/ForwardDeclarations.hpp" | ||
#include "Pomdog/Network/HTTPMethod.hpp" | ||
#include "Pomdog/Signals/Delegate.hpp" | ||
#include "Pomdog/Utility/Errors.hpp" | ||
#include <functional> | ||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace Pomdog { | ||
|
||
class POMDOG_EXPORT HTTPRequest final { | ||
public: | ||
static std::shared_ptr<HTTPRequest> | ||
Create(HTTPMethod method, const std::string& url); | ||
|
||
void AddHeader(const std::string& key, const std::string& value); | ||
|
||
public: | ||
/// The URL for the request (e.g. "https://example.com") | ||
std::string URL; | ||
|
||
/// The request headers | ||
std::vector<std::pair<std::string, std::string>> Headers; | ||
|
||
/// The request body | ||
std::vector<char> Body; | ||
|
||
/// Callback function that will be called on request completion or error caused | ||
Delegate<void(std::unique_ptr<HTTPResponse>&&, const std::shared_ptr<Error>&)> OnCompleted; | ||
|
||
/// The method for the request | ||
HTTPMethod Method; | ||
|
||
bool PersistentConnection = true; | ||
}; | ||
|
||
} // namespace Pomdog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) 2013-2019 mogemimi. Distributed under the MIT license. | ||
|
||
#pragma once | ||
|
||
#include "Pomdog/Basic/Export.hpp" | ||
#include "Pomdog/Network/detail/ForwardDeclarations.hpp" | ||
#include <cstddef> | ||
#include <functional> | ||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace Pomdog { | ||
|
||
class POMDOG_EXPORT HTTPResponse final { | ||
public: | ||
/// e.g. "200 OK" | ||
std::string Status; | ||
|
||
/// e.g. 200 | ||
int StatusCode; | ||
|
||
/// e.g. HTTP/1.1 | ||
std::string Protocol; | ||
|
||
std::vector<std::pair<std::string, std::string>> Header; | ||
|
||
std::vector<char> Body; | ||
|
||
std::size_t ContentLength = 0; | ||
|
||
/// True if "Transfer-Encoding" has a "chunked" directive, false otherwise. | ||
bool ChunkedTransferEncoding = false; | ||
|
||
std::shared_ptr<HTTPRequest> Request; | ||
}; | ||
|
||
} // namespace Pomdog |
Oops, something went wrong.