Added some basic HTTP and ip address parsing.

This commit is contained in:
2024-08-18 23:06:09 +02:00
parent 03c899f17e
commit 35e7131780
9 changed files with 497 additions and 35 deletions

55
source/mijin/net/http.hpp Normal file
View 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)