From 759fbff303159bbf051687b60b8b35c32700053e Mon Sep 17 00:00:00 2001 From: mbandic Date: Wed, 30 Aug 2023 11:54:14 +0000 Subject: [PATCH] Add header for http_response.. try 2 --- lib/http.hpp | 4 ++-- src/http.cpp | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/http.hpp b/lib/http.hpp index c051f80..65d4044 100644 --- a/lib/http.hpp +++ b/lib/http.hpp @@ -51,8 +51,8 @@ class http_response { void get(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 204a47b..35e69fc 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -85,15 +85,20 @@ void http_response::get(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 = "HTTP/1.1 200 OK\r\n"; // implementirati status if (!headers.empty()) { - raw += '?'; for (auto i : headers) { raw += i.first + ": " + i.second + "\r\n"; }