Added exceptions

dev v0.1_beta
marcelb 1 year ago
parent 8f6881af92
commit 394e4aa923
  1. 4
      src/api.cpp
  2. 12
      src/http.cpp

@ -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());
}
// radi
api::api(defapi* _def, const string _method, const string _path, const map<string, string> _params, const string _body) {
def = _def;
method = _method;
@ -28,11 +27,10 @@ api::api(defapi* _def, const string _method, const string _path, const map<strin
body = _body;
if (!validate()) {
cout << "Nije ispravan API" << endl;
throw "[ERROR] The API is not correct ";
}
}
// radi
api::api(defapi* _def, const http_request _req) {
def = _def;
method = _req.method;

@ -1,7 +1,5 @@
#include "../lib/http.hpp"
// radi
http_request::http_request(const string _method, const string _url, const string _body) {
method = _method;
url = _url;
@ -9,7 +7,6 @@ http_request::http_request(const string _method, const string _url, const string
mold();
}
// radi
http_request::http_request(const api *_api) {
method = _api->method;
url = _api->url;
@ -17,13 +14,11 @@ http_request::http_request(const api *_api) {
mold();
}
// radi
http_request::http_request(const string _raw) {
raw = _raw;
parse();
}
// radi
void http_request::parse() {
method = raw.substr(0, 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));
}
// ne radi za specijalan slučaj kada nema zaglavlja
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"));
@ -60,7 +54,6 @@ void http_request::putheaders(const map<string, string> _headers) {
/**
* http zahtjev formiranje raw
*/
// radi
void http_request::mold() {
@ -88,12 +81,12 @@ void http_response::get(const string _raw) {
}
/**
* Nakon
*
*/
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()) {
raw += '?';
for (auto i : headers) {
@ -104,7 +97,6 @@ void http_response::mold() {
raw += "\r\n" + body;
}
// radi
void http_response::parse() {

Loading…
Cancel
Save