Add my namespace
This commit is contained in:
parent
f0b08d4f52
commit
2baef56630
@ -9,6 +9,8 @@
|
|||||||
// #include "elementary.hpp"
|
// #include "elementary.hpp"
|
||||||
#include "http.hpp"
|
#include "http.hpp"
|
||||||
|
|
||||||
|
namespace marcelb {
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class http_request;
|
class http_request;
|
||||||
@ -28,4 +30,7 @@ class api {
|
|||||||
api(const http_request _req);
|
api(const http_request _req);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
#define _HTTP_ELMY_
|
#define _HTTP_ELMY_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
namespace marcelb {
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@ -109,4 +112,7 @@ typedef enum {
|
|||||||
|
|
||||||
string http_response_code_txt(uint code);
|
string http_response_code_txt(uint code);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -8,6 +8,8 @@
|
|||||||
#include "elementary.hpp"
|
#include "elementary.hpp"
|
||||||
#include "api.hpp"
|
#include "api.hpp"
|
||||||
|
|
||||||
|
namespace marcelb {
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class api;
|
class api;
|
||||||
@ -60,4 +62,6 @@ class http_response {
|
|||||||
|
|
||||||
static string set_protcol(const string _protocol);
|
static string set_protcol(const string _protocol);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "../lib/api.hpp"
|
#include "../lib/api.hpp"
|
||||||
|
|
||||||
api::api(const http_method _method, const string _path, const map<string, string> _params, const string _body) {
|
marcelb::api::api(const http_method _method, const string _path, const map<string, string> _params, const string _body) {
|
||||||
method = http_method_to_str(_method);
|
method = http_method_to_str(_method);
|
||||||
path = _path;
|
path = _path;
|
||||||
url = path;
|
url = path;
|
||||||
@ -17,7 +17,7 @@ api::api(const http_method _method, const string _path, const map<string, string
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
api::api(const http_request _req) {
|
marcelb::api::api(const http_request _req) {
|
||||||
method = _req.method;
|
method = _req.method;
|
||||||
//path = _path;
|
//path = _path;
|
||||||
url = _req.url;
|
url = _req.url;
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#include "../lib/elementary.hpp"
|
#include "../lib/elementary.hpp"
|
||||||
|
|
||||||
string http_method_to_str(http_method methode) {
|
using namespace std;
|
||||||
|
|
||||||
|
string marcelb::http_method_to_str(marcelb::http_method methode) {
|
||||||
string methode_str;
|
string methode_str;
|
||||||
switch (methode) {
|
switch (methode) {
|
||||||
case 0:
|
case 0:
|
||||||
@ -26,7 +28,7 @@ string http_method_to_str(http_method methode) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
string http_response_code_txt(uint code) {
|
string marcelb::http_response_code_txt(uint code) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
//####### 1xx - Informational #######
|
//####### 1xx - Informational #######
|
||||||
case 100: return "Continue";
|
case 100: return "Continue";
|
||||||
|
26
src/http.cpp
26
src/http.cpp
@ -1,6 +1,8 @@
|
|||||||
#include "../lib/http.hpp"
|
#include "../lib/http.hpp"
|
||||||
|
|
||||||
http_request::http_request(const http_method _method, const string _url, const string _body, const string _protocol) {
|
using namespace std;
|
||||||
|
|
||||||
|
marcelb::http_request::http_request(const http_method _method, const string _url, const string _body, const string _protocol) {
|
||||||
method = http_method_to_str(_method);
|
method = http_method_to_str(_method);
|
||||||
url = _url;
|
url = _url;
|
||||||
body = _body;
|
body = _body;
|
||||||
@ -8,7 +10,7 @@ http_request::http_request(const http_method _method, const string _url, const s
|
|||||||
mold();
|
mold();
|
||||||
}
|
}
|
||||||
|
|
||||||
http_request::http_request(const api *_api, const string _protocol) {
|
marcelb::http_request::http_request(const api *_api, const string _protocol) {
|
||||||
method = _api->method;
|
method = _api->method;
|
||||||
url = _api->url;
|
url = _api->url;
|
||||||
body = _api->body;
|
body = _api->body;
|
||||||
@ -16,12 +18,12 @@ http_request::http_request(const api *_api, const string _protocol) {
|
|||||||
mold();
|
mold();
|
||||||
}
|
}
|
||||||
|
|
||||||
http_request::http_request(const string _raw) {
|
marcelb::http_request::http_request(const string _raw) {
|
||||||
raw = _raw;
|
raw = _raw;
|
||||||
parse();
|
parse();
|
||||||
}
|
}
|
||||||
|
|
||||||
void http_request::parse() {
|
void marcelb::http_request::parse() {
|
||||||
|
|
||||||
if (raw.empty()) {
|
if (raw.empty()) {
|
||||||
return;
|
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;
|
headers[_key] = _value;
|
||||||
mold();
|
mold();
|
||||||
}
|
}
|
||||||
|
|
||||||
void http_request::setheaders(const map<string, string> _headers) {
|
void marcelb::http_request::setheaders(const map<string, string> _headers) {
|
||||||
headers = _headers;
|
headers = _headers;
|
||||||
mold();
|
mold();
|
||||||
}
|
}
|
||||||
@ -62,7 +64,7 @@ void http_request::setheaders(const map<string, string> _headers) {
|
|||||||
* http zahtjev formiranje raw
|
* http zahtjev formiranje raw
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void http_request::mold() {
|
void marcelb::http_request::mold() {
|
||||||
|
|
||||||
raw = method.empty() ? "GET" : method;
|
raw = method.empty() ? "GET" : method;
|
||||||
raw += " " + url + " HTTP/1.1\r\n";
|
raw += " " + url + " HTTP/1.1\r\n";
|
||||||
@ -76,7 +78,7 @@ void http_request::mold() {
|
|||||||
raw += "\r\n" + body;
|
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);
|
status = to_string(_status) + " " + http_response_code_txt(_status);
|
||||||
body = _body;
|
body = _body;
|
||||||
protocol = set_protcol(_protocol);
|
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;
|
raw = _raw;
|
||||||
parse();
|
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
|
raw = protocol + " " + status + "\r\n"; //"HTTP/1.1 200 OK\r\n"; // implementirati status
|
||||||
if (!headers.empty()) {
|
if (!headers.empty()) {
|
||||||
raw += '?';
|
raw += '?';
|
||||||
@ -107,7 +109,7 @@ void http_response::mold() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void http_response::parse() {
|
void marcelb::http_response::parse() {
|
||||||
|
|
||||||
if (raw.empty()) {
|
if (raw.empty()) {
|
||||||
return;
|
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;
|
string protocol;
|
||||||
if (_protocol == "1.0" || _protocol == "1.1" || _protocol == "2.0") {
|
if (_protocol == "1.0" || _protocol == "1.1" || _protocol == "2.0") {
|
||||||
protocol = "HTTP/" + _protocol;
|
protocol = "HTTP/" + _protocol;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "../lib/api.hpp"
|
#include "../lib/api.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace marcelb;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ int main() {
|
|||||||
cout << myres.body << endl;
|
cout << myres.body << endl;
|
||||||
|
|
||||||
|
|
||||||
http_response myres2(OK, "nnotauth", "1.0" );
|
http_response myres2(OK, "notauth", "1.0" );
|
||||||
cout << myres2.protocol << endl;
|
cout << myres2.protocol << endl;
|
||||||
cout << myres2.status << endl;
|
cout << myres2.status << endl;
|
||||||
// cout << myres2.headers << endl;
|
// cout << myres2.headers << endl;
|
||||||
|
BIN
test/test.o
BIN
test/test.o
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user