-
Notifications
You must be signed in to change notification settings - Fork 2
/
Stream.cpp
35 lines (26 loc) · 947 Bytes
/
Stream.cpp
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
#include "Date.h"
#include "Stream.h"
using namespace shitty;
static const std::string PRODUCT("Shitty");
static void setDateHeader(Headers& headers) {
// Ideally the client sets the Date header immediately *before* generating
// the response (RFC 7231 § 7.1.1.2 "Date" para. 3), so it might already be
// set to some time in the recent past.
if (headers.kv_.find("date") != headers.kv_.end())
return;
headers.kv_.emplace("date", Date::now());
}
static void setServerHeader(Headers& headers) {
if (headers.kv_.find("server") != headers.kv_.end())
return;
headers.kv_.emplace("server", PRODUCT);
}
void Stream::setGeneralServerHeaders(Headers& headers) {
setDateHeader(headers);
setServerHeader(headers);
}
void Stream::setUserAgentHeader(Headers& headers) {
if (headers.kv_.find("user-agent") != headers.kv_.end())
return;
headers.kv_.emplace("user-agent", PRODUCT);
}