forked from awwit/httpserverapp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerHttp1.cpp
More file actions
24 lines (17 loc) · 766 Bytes
/
ServerHttp1.cpp
File metadata and controls
24 lines (17 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "ServerHttp1.h"
namespace HttpServer
{
ServerHttp1::ServerHttp1(Socket::Adapter *sock) : ServerProtocol(sock) {}
bool ServerHttp1::sendHeaders(const Http::StatusCode status, std::vector<std::pair<std::string, std::string> > &headers, const std::chrono::milliseconds &timeout, const bool endStream) const
{
std::string out = "HTTP/1.1 " + std::to_string(static_cast<int>(status) ) + "\r\n";
for (auto const &h : headers) {
out += h.first + ": " + h.second + "\r\n";
}
out += "\r\n";
return this->sock->nonblock_send(out, timeout) > 0;
}
long ServerHttp1::sendData(const void *src, const size_t size, const std::chrono::milliseconds &timeout, const bool endStream) const {
return this->sock->nonblock_send(src, size, timeout);
}
}