|
|
@ -1,7 +1,5 @@ |
|
|
|
#include "../lib/http.hpp" |
|
|
|
#include "../lib/http.hpp" |
|
|
|
|
|
|
|
|
|
|
|
// radi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
http_request::http_request(const string _method, const string _url, const string _body) { |
|
|
|
http_request::http_request(const string _method, const string _url, const string _body) { |
|
|
|
method = _method; |
|
|
|
method = _method; |
|
|
|
url = _url; |
|
|
|
url = _url; |
|
|
@ -9,7 +7,6 @@ http_request::http_request(const string _method, const string _url, const string |
|
|
|
mold(); |
|
|
|
mold(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// radi
|
|
|
|
|
|
|
|
http_request::http_request(const api *_api) { |
|
|
|
http_request::http_request(const api *_api) { |
|
|
|
method = _api->method; |
|
|
|
method = _api->method; |
|
|
|
url = _api->url; |
|
|
|
url = _api->url; |
|
|
@ -17,13 +14,11 @@ http_request::http_request(const api *_api) { |
|
|
|
mold(); |
|
|
|
mold(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// radi
|
|
|
|
|
|
|
|
http_request::http_request(const string _raw) { |
|
|
|
http_request::http_request(const string _raw) { |
|
|
|
raw = _raw; |
|
|
|
raw = _raw; |
|
|
|
parse(); |
|
|
|
parse(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// radi
|
|
|
|
|
|
|
|
void http_request::parse() { |
|
|
|
void http_request::parse() { |
|
|
|
method = raw.substr(0, raw.find(" ")); |
|
|
|
method = raw.substr(0, raw.find(" ")); |
|
|
|
url = raw.substr(raw.find("/"), raw.find("HTTP/")-raw.find("/")); |
|
|
|
url = raw.substr(raw.find("/"), raw.find("HTTP/")-raw.find("/")); |
|
|
@ -38,7 +33,6 @@ void http_request::parse() { |
|
|
|
headers.insert(make_pair(key, value)); |
|
|
|
headers.insert(make_pair(key, value)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ne radi za specijalan slučaj kada nema zaglavlja
|
|
|
|
|
|
|
|
if ((size_t)raw.find("\r\n\r\n") == (size_t)raw.find("\r\n")) |
|
|
|
if ((size_t)raw.find("\r\n\r\n") == (size_t)raw.find("\r\n")) |
|
|
|
body = raw.substr(raw.find("\r\n\r\n")+4, raw.length()-raw.find("\r\n\r\n")); |
|
|
|
body = raw.substr(raw.find("\r\n\r\n")+4, raw.length()-raw.find("\r\n\r\n")); |
|
|
|
|
|
|
|
|
|
|
@ -60,7 +54,6 @@ void http_request::putheaders(const map<string, string> _headers) { |
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* http zahtjev formiranje raw
|
|
|
|
* http zahtjev formiranje raw
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
// radi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void http_request::mold() { |
|
|
|
void http_request::mold() { |
|
|
|
|
|
|
|
|
|
|
@ -88,12 +81,12 @@ void http_response::get(const string _raw) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Nakon
|
|
|
|
*
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void http_response::mold() { |
|
|
|
void http_response::mold() { |
|
|
|
raw = "HTTP/1.1 200 OK\r\n"; |
|
|
|
raw = "HTTP/1.1 200 OK\r\n"; // implementirati status
|
|
|
|
if (!headers.empty()) { |
|
|
|
if (!headers.empty()) { |
|
|
|
raw += '?'; |
|
|
|
raw += '?'; |
|
|
|
for (auto i : headers) { |
|
|
|
for (auto i : headers) { |
|
|
@ -104,7 +97,6 @@ void http_response::mold() { |
|
|
|
raw += "\r\n" + body; |
|
|
|
raw += "\r\n" + body; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// radi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void http_response::parse() { |
|
|
|
void http_response::parse() { |
|
|
|
|
|
|
|
|
|
|
|