diff --git a/lib/http.hpp b/lib/http.hpp index c0a5eca..3d7c03d 100644 --- a/lib/http.hpp +++ b/lib/http.hpp @@ -51,8 +51,8 @@ class http_response { http_response(const string _raw); //bool validate(); - // void putheader(const string _key, const string _value); - // void putheaders(const map _headers); + void header(const string _key, const string _value); + void header(const map _headers); void mold(); // za slanje void parse(); // Ĩitaj http diff --git a/src/http.cpp b/src/http.cpp index 18dc444..0bd7e28 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -89,15 +89,20 @@ http_response::http_response(const string _raw) { parse(); } -/** - * -*/ +void http_response::header(const string _key, const string _value) { + headers[_key] = _value; + mold(); +} + +void http_response::header(const map _headers) { + headers = _headers; + mold(); +} void http_response::mold() { raw = protocol + " " + status + "\r\n"; //"HTTP/1.1 200 OK\r\n"; // implementirati status if (!headers.empty()) { - raw += '?'; for (auto i : headers) { raw += i.first + ": " + i.second + "\r\n"; } diff --git a/test/test.cpp b/test/test.cpp index aca7c14..40083d7 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -49,19 +49,15 @@ int main() { // myres.get("HTTP/1.1 200 OK\r\n\r\nnotauth"); // myres.get("HTTP/1.1 200 OK"); - + // myres.header("Content-type", "text/plain"); // api uf(&myApi, myres); - // cout << uf.method << " " << uf.path << " " << uf.body << endl; - // cout << myres.method << " " << myres.url << " " << myres.body << endl << myres.raw << endl; + // cout << uf.method << " " << uf.path << " " << uf.body << endl;// << myres.raw; + // cout << myres.method << " " << myres.url << " " << myres.body << endl;// << myres.raw; // for(auto i : uf.params) // cout << i.first << " " << i.second << endl; - } catch (string err) { - cout << err << endl; - } - }