-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpRequest.cpp
More file actions
32 lines (28 loc) · 924 Bytes
/
HttpRequest.cpp
File metadata and controls
32 lines (28 loc) · 924 Bytes
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
#include "HttpRequest.h"
#include <sstream>
#include <iostream>
void HttpRequest::parse(const std::string& rawRequest) {
std::istringstream stream(rawRequest);
std::string line;
// Primera línea: GET /index.html HTTP/1.1
if (std::getline(stream, line)) {
std::istringstream lineStream(line);
lineStream >> method >> path >> version;
}
// Headers
while (std::getline(stream, line) && line != "\r") {
auto colon = line.find(':');
if (colon != std::string::npos) {
std::string key = line.substr(0, colon);
std::string value = line.substr(colon + 1);
// Quitar espacios iniciales
if (!value.empty() && value[0] == ' ') value.erase(0, 1);
headers[key] = value;
}
}
// Body (si hay)
std::string bodyContent;
while (std::getline(stream, line)) {
body += line + "\n";
}
}