-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathServerHttp1.cpp
More file actions
41 lines (33 loc) · 824 Bytes
/
ServerHttp1.cpp
File metadata and controls
41 lines (33 loc) · 824 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "ServerHttp1.h"
namespace HttpServer
{
ServerHttp1::ServerHttp1(Socket::Adapter *sock) noexcept
: 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 noexcept {
return this->sock->nonblock_send(
src,
size,
timeout
);
}
}