Added exceptions
This commit is contained in:
parent
8f6881af92
commit
394e4aa923
@ -10,7 +10,6 @@ void defapi::necessary(const string _path, const vector<string> _keys) {
|
|||||||
val_matrix[_path].insert( val_matrix[_path].end(), _keys.begin(), _keys.end());
|
val_matrix[_path].insert( val_matrix[_path].end(), _keys.begin(), _keys.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
// radi
|
|
||||||
api::api(defapi* _def, const string _method, const string _path, const map<string, string> _params, const string _body) {
|
api::api(defapi* _def, const string _method, const string _path, const map<string, string> _params, const string _body) {
|
||||||
def = _def;
|
def = _def;
|
||||||
method = _method;
|
method = _method;
|
||||||
@ -28,11 +27,10 @@ api::api(defapi* _def, const string _method, const string _path, const map<strin
|
|||||||
body = _body;
|
body = _body;
|
||||||
|
|
||||||
if (!validate()) {
|
if (!validate()) {
|
||||||
cout << "Nije ispravan API" << endl;
|
throw "[ERROR] The API is not correct ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// radi
|
|
||||||
api::api(defapi* _def, const http_request _req) {
|
api::api(defapi* _def, const http_request _req) {
|
||||||
def = _def;
|
def = _def;
|
||||||
method = _req.method;
|
method = _req.method;
|
||||||
|
12
src/http.cpp
12
src/http.cpp
@ -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() {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user