MCPcopy Create free account
hub / github.com/davisking/dlib / parse_http_request

Function parse_http_request

dlib/server/server_http.cpp:156–297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

154// ----------------------------------------------------------------------------------------
155
156 unsigned long parse_http_request (
157 std::istream& in,
158 incoming_things& incoming,
159 unsigned long max_content_length
160 )
161 {
162 using namespace std;
163 using namespace http_impl;
164 read_with_limit(in, incoming.request_type, ' ');
165
166 // get the path
167 read_with_limit(in, incoming.path, ' ');
168
169 // Get the HTTP/1.1 - Ignore for now...
170 read_with_limit(in, incoming.protocol);
171
172 key_value_map_ci& incoming_headers = incoming.headers;
173 key_value_map& cookies = incoming.cookies;
174 std::string& path = incoming.path;
175 std::string& content_type = incoming.content_type;
176 unsigned long content_length = 0;
177
178 string line;
179 read_with_limit(in, line);
180 string first_part_of_header;
181 string::size_type position_of_double_point;
182 // now loop over all the incoming_headers
183 while (line != "\r")
184 {
185 position_of_double_point = line.find_first_of(':');
186 if ( position_of_double_point != string::npos )
187 {
188 first_part_of_header = dlib::trim(line.substr(0, position_of_double_point));
189
190 if ( !incoming_headers[first_part_of_header].empty() )
191 incoming_headers[ first_part_of_header ] += " ";
192 incoming_headers[first_part_of_header] += dlib::trim(line.substr(position_of_double_point+1));
193
194 // look for Content-Type:
195 if (line.size() > 14 && strings_equal_ignore_case(line, "Content-Type:", 13))
196 {
197 content_type = line.substr(14);
198 if (content_type[content_type.size()-1] == '\r')
199 content_type.erase(content_type.size()-1);
200 }
201 // look for Content-Length:
202 else if (line.size() > 16 && strings_equal_ignore_case(line, "Content-Length:", 15))
203 {
204 istringstream sin(line.substr(16));
205 sin >> content_length;
206 if (!sin)
207 {
208 throw http_parse_error("Invalid Content-Length of '" + line.substr(16) + "'", 411);
209 }
210
211 if (content_length > max_content_length)
212 {
213 std::ostringstream sout;

Callers 2

on_connectMethod · 0.85
on_connectMethod · 0.85

Calls 14

read_with_limitFunction · 0.85
trimFunction · 0.85
urldecodeFunction · 0.85
left_substrFunction · 0.85
parse_urlFunction · 0.85
eraseMethod · 0.80
readMethod · 0.80
http_parse_errorClass · 0.70
emptyMethod · 0.45
sizeMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected