blob: 16e59c4d78c02b6bfd0748a4fd699a0893ec64bf (
plain) (
blame)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
#pragma once
#include <library/cpp/digest/lower_case/hash_ops.h>
#include <util/str_stl.h>
#include <util/system/defaults.h>
#include <util/string/cast.h>
#include <library/cpp/cgiparam/cgiparam.h>
#include <util/network/address.h>
#include <util/network/socket.h>
#include <util/generic/hash.h>
#include <util/system/yassert.h>
#include <util/generic/string.h>
#include <util/datetime/base.h>
#include <util/generic/buffer.h>
using THttpHeadersContainer = THashMap<TString, TString, TCIOps, TCIOps>;
class TBaseServerRequestData {
public:
TBaseServerRequestData(SOCKET s = INVALID_SOCKET);
TBaseServerRequestData(const char* qs, SOCKET s = INVALID_SOCKET);
void SetHost(const TString& host, ui16 port) {
Host = host;
Port = ToString(port);
}
const TString& ServerName() const {
return Host;
}
NAddr::IRemoteAddrPtr ServerAddress() const {
return NAddr::GetSockAddr(Socket);
}
const TString& ServerPort() const {
return Port;
}
const char* ScriptName() const {
return Path;
}
const char* QueryString() const {
return Search;
}
TStringBuf QueryStringBuf() const {
return TStringBuf(Search, SearchLength);
}
TStringBuf OrigQueryStringBuf() const {
return OrigSearch;
}
void AppendQueryString(const char* str, size_t length);
const char* RemoteAddr() const;
void SetRemoteAddr(TStringBuf addr);
const char* HeaderIn(TStringBuf key) const;
const THttpHeadersContainer& HeadersIn() const {
return HeadersIn_;
}
inline size_t HeadersCount() const noexcept {
return HeadersIn_.size();
}
TString HeaderByIndex(size_t n) const noexcept;
const char* Environment(const char* key) const;
void Clear();
void SetSocket(SOCKET s) noexcept {
Socket = s;
}
ui64 RequestBeginTime() const noexcept {
return BeginTime;
}
void SetPath(const TString& path);
const char* GetCurPage() const;
bool Parse(const char* req);
void AddHeader(const TString& name, const TString& value);
private:
TBuffer PathStorage;
mutable char* Addr;
TString Host;
TString Port;
char* Path;
char* Search;
size_t SearchLength; // length of Search
TStringBuf OrigSearch;
THttpHeadersContainer HeadersIn_;
mutable char AddrData[INET6_ADDRSTRLEN];
SOCKET Socket;
ui64 BeginTime;
mutable TString CurPage;
TBuffer ParseBuf;
TBuffer ModifiedQueryString;
};
class TServerRequestData: public TBaseServerRequestData {
public:
TServerRequestData(SOCKET s = INVALID_SOCKET)
: TBaseServerRequestData(s)
{
}
TServerRequestData(const char* qs, SOCKET s = INVALID_SOCKET)
: TBaseServerRequestData(qs, s)
{
Scan();
}
void Scan() {
CgiParam.Scan(QueryStringBuf());
}
public:
TCgiParameters CgiParam;
};
|