-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.cpp
More file actions
35 lines (24 loc) · 779 Bytes
/
app.cpp
File metadata and controls
35 lines (24 loc) · 779 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
33
34
35
#include <iostream>
#include <winsock2.h>
#include "WS/app.h"
std::string parseReq(char req[1024]) {
std::string request(req);
size_t newline_pos = request.find("\r\n");
if (newline_pos == std::string::npos) return "";
std::string first_line = request.substr(0, newline_pos);
size_t pos = first_line.find(" ");
if (pos == std::string::npos) return "";
size_t ps = pos + 1;
size_t pe = first_line.find(" ", ps);
if (pe == std::string::npos) return "";
return first_line.substr(ps, pe - ps);
}
void Handle(SOCKET client, char response[1024]) {
std::string resp = parseReq(response);
std::cout << resp;
if (resp == "/") {
SEND(client, "index.html");
} else {
SEND(client, "not_found.html");
}
}