Added some basic HTTP and ip address parsing.
This commit is contained in:
55
source/mijin/net/http.hpp
Normal file
55
source/mijin/net/http.hpp
Normal file
@@ -0,0 +1,55 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined(MIJIN_NET_HTTP_HPP_INCLUDED)
|
||||
#define MIJIN_NET_HTTP_HPP_INCLUDED 1
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "../io/stream.hpp"
|
||||
|
||||
namespace mijin
|
||||
{
|
||||
struct HTTPVersion
|
||||
{
|
||||
unsigned major;
|
||||
unsigned minor;
|
||||
};
|
||||
|
||||
struct HTTPRequest
|
||||
{
|
||||
std::string address;
|
||||
std::string method = "GET";
|
||||
std::multimap<std::string, std::string> headers;
|
||||
std::string body;
|
||||
|
||||
explicit HTTPRequest(std::string address_) noexcept : address(std::move(address_)) {}
|
||||
};
|
||||
|
||||
struct HTTPResponse
|
||||
{
|
||||
HTTPVersion version;
|
||||
unsigned status;
|
||||
std::string statusMessage;
|
||||
std::multimap<std::string, std::string> headers;
|
||||
std::string content;
|
||||
};
|
||||
|
||||
class HTTPStream
|
||||
{
|
||||
private:
|
||||
Stream* base_;
|
||||
public:
|
||||
HTTPStream(Stream& base) noexcept : base_(&base)
|
||||
{
|
||||
MIJIN_ASSERT(base_ != nullptr, "Invalid parameter for base.");
|
||||
}
|
||||
Task<StreamResult<HTTPResponse>> c_request(HTTPRequest request) noexcept;
|
||||
private:
|
||||
Task<StreamError> c_writeRequest(const HTTPRequest& request) noexcept;
|
||||
Task<StreamResult<HTTPResponse>> c_readResponse() noexcept;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !defined(MIJIN_NET_HTTP_HPP_INCLUDED)
|
||||
Reference in New Issue
Block a user