modified http protocol to use DataStream

multi_plaform
anulax1225 ago%!(EXTRA string=1 year)
parent fa051c15d5
commit a0a9eec20d
  1. 1
      bakanet/src/bakanet/http/http_packet.h
  2. 5
      bakanet/src/bakanet/http/http_server.cpp
  3. 9
      bakanet/src/bakanet/http/http_server.h

@ -1,7 +1,6 @@
#pragma once
#include <bakanetpch.h>
#include <bakatools.h>
#define HTTP_RES_200 "200 OK"

@ -2,7 +2,6 @@
namespace Bk::Net {
HttpServer::HttpServer(IpAddress ip, int port)
{
Bk::Log::init("BAKANET");
BK_CORE_INFO("NEW SERVER");
socket = Socket::create(ip, port, IpProtocol::TCP);
radix = RadixTree();
@ -32,7 +31,7 @@ namespace Bk::Net {
HttpRequest HttpServer::recv_request(Socket& conn)
{
Packet req;
Type::DataStream req;
std::vector<char> data;
do
{
@ -46,7 +45,7 @@ namespace Bk::Net {
void HttpServer::send_reponse(Socket& conn, HttpReponse res)
{
Packet res_packet;
Type::DataStream res_packet;
std::string str_res = res.to_string();
res_packet.push<char>(str_res.c_str(), str_res.length());
conn.emit(res_packet.payload);

@ -1,19 +1,18 @@
#pragma once
#include <bakanetpch.h>
#include <bakatools.h>
#include <bakanet/core/ip_address.h>
#include <bakanet/core/packet.h>
#include <bakanet/core/socket.h>
#include "http_packet.h"
namespace Bk::Net {
class HttpServer
{
using RequestHandler = std::function<HttpReponse(HttpRequest& req)>;
using HttpMethodArray = std::unordered_map<std::string, RequestHandler>;
using RadixTree = DataType::Trie<std::string, HttpMethodArray>;
using RadixTree = Type::Trie<std::string, HttpMethodArray>;
using ThreadPool = std::vector<std::thread>;
class HttpServer
{
public:
HttpServer(IpAddress ip, int port);
~HttpServer() = default;

Loading…
Cancel
Save