diff --git a/lib/api.hpp b/lib/api.hpp index 712c216..24f078a 100644 --- a/lib/api.hpp +++ b/lib/api.hpp @@ -9,6 +9,8 @@ // #include "elementary.hpp" #include "http.hpp" +namespace marcelb { + using namespace std; class http_request; @@ -28,4 +30,7 @@ class api { api(const http_request _req); }; + +} + #endif diff --git a/lib/elementary.hpp b/lib/elementary.hpp index 23b002a..ac870d3 100644 --- a/lib/elementary.hpp +++ b/lib/elementary.hpp @@ -2,6 +2,9 @@ #define _HTTP_ELMY_ #include + +namespace marcelb { + using namespace std; typedef enum { @@ -109,4 +112,7 @@ typedef enum { string http_response_code_txt(uint code); + +} + #endif \ No newline at end of file diff --git a/lib/http.hpp b/lib/http.hpp index c0a5eca..c7b8f06 100644 --- a/lib/http.hpp +++ b/lib/http.hpp @@ -8,6 +8,8 @@ #include "elementary.hpp" #include "api.hpp" +namespace marcelb { + using namespace std; class api; @@ -60,4 +62,6 @@ class http_response { static string set_protcol(const string _protocol); +} + #endif diff --git a/src/api.cpp b/src/api.cpp index 9dda409..4a4f805 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -1,6 +1,6 @@ #include "../lib/api.hpp" -api::api(const http_method _method, const string _path, const map _params, const string _body) { +marcelb::api::api(const http_method _method, const string _path, const map _params, const string _body) { method = http_method_to_str(_method); path = _path; url = path; @@ -17,7 +17,7 @@ api::api(const http_method _method, const string _path, const mapmethod; url = _api->url; body = _api->body; @@ -16,12 +18,12 @@ http_request::http_request(const api *_api, const string _protocol) { mold(); } -http_request::http_request(const string _raw) { +marcelb::http_request::http_request(const string _raw) { raw = _raw; parse(); } -void http_request::parse() { +void marcelb::http_request::parse() { if (raw.empty()) { return; @@ -48,12 +50,12 @@ void http_request::parse() { } -void http_request::putheader(const string _key, const string _value) { +void marcelb::http_request::putheader(const string _key, const string _value) { headers[_key] = _value; mold(); } -void http_request::setheaders(const map _headers) { +void marcelb::http_request::setheaders(const map _headers) { headers = _headers; mold(); } @@ -62,7 +64,7 @@ void http_request::setheaders(const map _headers) { * http zahtjev formiranje raw */ -void http_request::mold() { +void marcelb::http_request::mold() { raw = method.empty() ? "GET" : method; raw += " " + url + " HTTP/1.1\r\n"; @@ -76,7 +78,7 @@ void http_request::mold() { raw += "\r\n" + body; } -http_response::http_response(const http_response_code _status, const string _body, const string _protocol) { +marcelb::http_response::http_response(const http_response_code _status, const string _body, const string _protocol) { status = to_string(_status) + " " + http_response_code_txt(_status); body = _body; protocol = set_protcol(_protocol); @@ -84,7 +86,7 @@ http_response::http_response(const http_response_code _status, const string _bod } -http_response::http_response(const string _raw) { +marcelb::http_response::http_response(const string _raw) { raw = _raw; parse(); } @@ -94,7 +96,7 @@ http_response::http_response(const string _raw) { */ -void http_response::mold() { +void marcelb::http_response::mold() { raw = protocol + " " + status + "\r\n"; //"HTTP/1.1 200 OK\r\n"; // implementirati status if (!headers.empty()) { raw += '?'; @@ -107,7 +109,7 @@ void http_response::mold() { } -void http_response::parse() { +void marcelb::http_response::parse() { if (raw.empty()) { return; @@ -136,7 +138,7 @@ void http_response::parse() { } -static string set_protcol(const string _protocol) { +static string marcelb::set_protcol(const string _protocol) { string protocol; if (_protocol == "1.0" || _protocol == "1.1" || _protocol == "2.0") { protocol = "HTTP/" + _protocol; diff --git a/test/test.cpp b/test/test.cpp index aca7c14..b4b7ca3 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -3,6 +3,7 @@ #include "../lib/api.hpp" using namespace std; +using namespace marcelb; int main() { @@ -21,7 +22,7 @@ int main() { cout << myres.body << endl; - http_response myres2(OK, "nnotauth", "1.0" ); + http_response myres2(OK, "notauth", "1.0" ); cout << myres2.protocol << endl; cout << myres2.status << endl; // cout << myres2.headers << endl; diff --git a/test/test.o b/test/test.o index 29cc6bf..864b3e2 100755 Binary files a/test/test.o and b/test/test.o differ