|
6 | 6 | /* By: aoumad <aoumad@student.42.fr> +#+ +:+ +#+ */ |
7 | 7 | /* +#+#+#+#+#+ +#+ */ |
8 | 8 | /* Created: 2023/03/26 23:05:21 by aoumad #+# #+# */ |
9 | | -/* Updated: 2023/05/05 16:33:19 by aoumad ### ########.fr */ |
| 9 | +/* Updated: 2023/05/08 16:17:03 by aoumad ### ########.fr */ |
10 | 10 | /* */ |
11 | 11 | /* ************************************************************************** */ |
12 | 12 |
|
@@ -119,6 +119,7 @@ void request::parse_request(std::string request) |
119 | 119 | lines.push_back(line); |
120 | 120 | } |
121 | 121 | // Parse the request line |
| 122 | + // std::cout << lines[0] << std::endl; |
122 | 123 | std::istringstream request_line(lines[0]); |
123 | 124 | request_line >> this->_method >> this->_uri >> this->_version; |
124 | 125 | // i need to call a function to check if the request line content is suitable or not |
@@ -164,62 +165,25 @@ void request::parse_request(std::string request) |
164 | 165 | exit(1); |
165 | 166 | } |
166 | 167 | ft_parse_port(this->get_header("Host")); |
167 | | - ft_parse_language_charset(); |
| 168 | + // ft_parse_language_charset(); |
168 | 169 |
|
169 | 170 | // Parse the request body |
170 | 171 | std::string content_len_str = this->get_header("Content-Length"); |
171 | | - if (!content_len_str.empty()) |
| 172 | + if (content_len_str != "") |
172 | 173 | { |
173 | 174 | size_t content_len = std::stoi(content_len_str); |
174 | 175 | this->_body = lines.back().substr(0, content_len); |
175 | | - // std::string transfer_encoding = this->get_header("Accept-Encoding"); |
176 | | - // if (!transfer_encoding.empty()) |
177 | | - // { |
178 | | - // // using pointers to member functions to call the functions handlers |
179 | | - // std::vector<std::string> encoding_types; |
180 | | - // size_t startPos = 0; |
181 | | - // size_t endPos = transfer_encoding.find(','); |
182 | | - // while (endPos != std::string::npos) |
183 | | - // { |
184 | | - // encoding_types.push_back(transfer_encoding.substr(startPos, endPos - startPos)); |
185 | | - // startPos = endPos + 1; |
186 | | - // endPos = transfer_encoding.find(',', startPos); |
187 | | - // } |
188 | | - // encoding_types.push_back(transfer_encoding.substr(startPos, endPos - startPos)); |
189 | | - // for (std::vector<std::string>::const_iterator it = encoding_types.begin(); it != encoding_types.end(); ++it) |
190 | | - // { |
191 | | - // std::string type_tmp = *it; |
192 | | - // // Trim leading and trailing whitespaces from the value |
193 | | - // // type_tmp.erase(0, type_tmp.find_first_not_of(" \t")); |
194 | | - // // type_tmp.erase(type_tmp.find_first_not_of(" \t") + 1); |
195 | | - // bool supported = false; |
196 | | - // for (size_t i = 0; i < sizeof(handlers) / sizeof(handlers[0]); ++i) |
197 | | - // { |
198 | | - // if (type_tmp == supported_encodings[i]) |
199 | | - // { |
200 | | - // (this->*handlers[i])(this->_body); |
201 | | - // supported = true; |
202 | | - // break; |
203 | | - // } |
204 | | - // } |
205 | | - // if (!supported) |
206 | | - // std::cerr << "Unsupported encoding type: " << type_tmp << std::endl; |
207 | | - // } |
208 | | - |
209 | | - // } |
210 | 176 | } |
211 | 177 | else |
212 | 178 | { |
213 | | - if (this->_headers.find("Content-Length") != this->_headers.end() || this->_method == "POST" || this->_method == "PUT" |
214 | | - || this->_headers.find("Content-Type") != this->_headers.end()) |
| 179 | + // std::cout << "____----_-_-_-_--_-_____-_-_-_-____-_-_-_-_-------" << std::endl; |
| 180 | + if (content_len_str == "" || this->_method == "POST") |
215 | 181 | { |
216 | | - std::cerr << "Body request is missing" << std::endl; |
217 | | - exit(1); |
| 182 | + set_body(""); |
| 183 | + return ; |
218 | 184 | } |
219 | 185 |
|
220 | 186 | } |
221 | | - |
222 | | - // print_request(); |
223 | 187 | } |
224 | 188 |
|
225 | 189 | void request::print_request() |
|
0 commit comments