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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
use std::{
borrow::Cow,
collections::HashMap,
ops::{Deref, DerefMut},
};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Params<'a>(HashMap<Cow<'a, str>, Cow<'a, str>>);
impl<'a> Params<'a> {
#[inline]
pub fn gateway_interface<S: Into<Cow<'a, str>>>(mut self, gateway_interface: S) -> Self {
self.insert("GATEWAY_INTERFACE".into(), gateway_interface.into());
self
}
#[inline]
pub fn server_software<S: Into<Cow<'a, str>>>(mut self, server_software: S) -> Self {
self.insert("SERVER_SOFTWARE".into(), server_software.into());
self
}
#[inline]
pub fn server_protocol<S: Into<Cow<'a, str>>>(mut self, server_protocol: S) -> Self {
self.insert("SERVER_PROTOCOL".into(), server_protocol.into());
self
}
#[inline]
pub fn request_method<S: Into<Cow<'a, str>>>(mut self, request_method: S) -> Self {
self.insert("REQUEST_METHOD".into(), request_method.into());
self
}
#[inline]
pub fn script_filename<S: Into<Cow<'a, str>>>(mut self, script_filename: S) -> Self {
self.insert("SCRIPT_FILENAME".into(), script_filename.into());
self
}
#[inline]
pub fn script_name<S: Into<Cow<'a, str>>>(mut self, script_name: S) -> Self {
self.insert("SCRIPT_NAME".into(), script_name.into());
self
}
#[inline]
pub fn query_string<S: Into<Cow<'a, str>>>(mut self, query_string: S) -> Self {
self.insert("QUERY_STRING".into(), query_string.into());
self
}
#[inline]
pub fn request_uri<S: Into<Cow<'a, str>>>(mut self, request_uri: S) -> Self {
self.insert("REQUEST_URI".into(), request_uri.into());
self
}
#[inline]
pub fn document_root<S: Into<Cow<'a, str>>>(mut self, document_root: S) -> Self {
self.insert("DOCUMENT_ROOT".into(), document_root.into());
self
}
#[inline]
pub fn document_uri<S: Into<Cow<'a, str>>>(mut self, document_uri: S) -> Self {
self.insert("DOCUMENT_URI".into(), document_uri.into());
self
}
#[inline]
pub fn remote_addr<S: Into<Cow<'a, str>>>(mut self, remote_addr: S) -> Self {
self.insert("REMOTE_ADDR".into(), remote_addr.into());
self
}
#[inline]
pub fn remote_port(mut self, remote_port: u16) -> Self {
self.insert("REMOTE_PORT".into(), remote_port.to_string().into());
self
}
#[inline]
pub fn server_addr<S: Into<Cow<'a, str>>>(mut self, server_addr: S) -> Self {
self.insert("SERVER_ADDR".into(), server_addr.into());
self
}
#[inline]
pub fn server_port(mut self, server_port: u16) -> Self {
self.insert("SERVER_PORT".into(), server_port.to_string().into());
self
}
#[inline]
pub fn server_name<S: Into<Cow<'a, str>>>(mut self, server_name: S) -> Self {
self.insert("SERVER_NAME".into(), server_name.into());
self
}
#[inline]
pub fn content_type<S: Into<Cow<'a, str>>>(mut self, content_type: S) -> Self {
self.insert("CONTENT_TYPE".into(), content_type.into());
self
}
#[inline]
pub fn content_length(mut self, content_length: usize) -> Self {
self.insert("CONTENT_LENGTH".into(), content_length.to_string().into());
self
}
}
impl<'a> Default for Params<'a> {
fn default() -> Self {
Params(HashMap::new())
.gateway_interface("FastCGI/1.0")
.server_software("fastcgi-client-rs")
.server_protocol("HTTP/1.1")
}
}
impl<'a> Deref for Params<'a> {
type Target = HashMap<Cow<'a, str>, Cow<'a, str>>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<'a> DerefMut for Params<'a> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl<'a> From<Params<'a>> for HashMap<Cow<'a, str>, Cow<'a, str>> {
fn from(params: Params<'a>) -> Self {
params.0
}
}