Merge branch 'header-response' into testing

namespace
mbandic 1 year ago
commit 6c281313de
  1. 4
      lib/http.hpp
  2. 13
      src/http.cpp
  3. 10
      test/test.cpp

@ -51,8 +51,8 @@ class http_response {
http_response(const string _raw); http_response(const string _raw);
//bool validate(); //bool validate();
// void putheader(const string _key, const string _value); void header(const string _key, const string _value);
// void putheaders(const map<string, string> _headers); void header(const map<string, string> _headers);
void mold(); // za slanje void mold(); // za slanje
void parse(); // čitaj http void parse(); // čitaj http

@ -89,15 +89,20 @@ http_response::http_response(const string _raw) {
parse(); parse();
} }
/** void http_response::header(const string _key, const string _value) {
* headers[_key] = _value;
*/ mold();
}
void http_response::header(const map<string, string> _headers) {
headers = _headers;
mold();
}
void http_response::mold() { void 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 += '?';
for (auto i : headers) { for (auto i : headers) {
raw += i.first + ": " + i.second + "\r\n"; raw += i.first + ": " + i.second + "\r\n";
} }

@ -49,19 +49,15 @@ int main() {
// myres.get("HTTP/1.1 200 OK\r\n\r\nnotauth"); // myres.get("HTTP/1.1 200 OK\r\n\r\nnotauth");
// myres.get("HTTP/1.1 200 OK"); // myres.get("HTTP/1.1 200 OK");
// myres.header("Content-type", "text/plain");
// api uf(&myApi, myres); // api uf(&myApi, myres);
// cout << uf.method << " " << uf.path << " " << uf.body << endl; // cout << uf.method << " " << uf.path << " " << uf.body << endl;// << myres.raw;
// cout << myres.method << " " << myres.url << " " << myres.body << endl << myres.raw << endl; // cout << myres.method << " " << myres.url << " " << myres.body << endl;// << myres.raw;
// for(auto i : uf.params) // for(auto i : uf.params)
// cout << i.first << " " << i.second << endl; // cout << i.first << " " << i.second << endl;
} catch (string err) {
cout << err << endl;
}
} }

Loading…
Cancel
Save