Commit 06b76563 authored by Mathieu Stefani's avatar Mathieu Stefani

Response API: function renaming

parent ad8e24eb
...@@ -18,7 +18,7 @@ class MyHandler : public Net::Http::Handler { ...@@ -18,7 +18,7 @@ class MyHandler : public Net::Http::Handler {
.add(std::make_shared<Header::Server>("lys")) .add(std::make_shared<Header::Server>("lys"))
.add(std::make_shared<Header::ContentType>(MIME(Text, Plain))); .add(std::make_shared<Header::ContentType>(MIME(Text, Plain)));
auto w = response.writer(Net::Http::Code::Ok); auto w = response.beginWrite(Net::Http::Code::Ok);
std::ostream os(w); std::ostream os(w);
os << "PONG"; os << "PONG";
......
...@@ -119,6 +119,10 @@ public: ...@@ -119,6 +119,10 @@ public:
return code_; return code_;
} }
void setCode(Code code) {
code_ = code;
}
std::streambuf* rdbuf() { std::streambuf* rdbuf() {
return &stream_; return &stream_;
} }
...@@ -191,7 +195,11 @@ public: ...@@ -191,7 +195,11 @@ public:
} }
void setMime(const Mime::MediaType& mime) { void setMime(const Mime::MediaType& mime) {
headers().add(std::make_shared<Header::ContentType>(mime)); auto ct = headers_.tryGet<Header::ContentType>();
if (ct)
ct->setMime(mime);
else
headers_.add(std::make_shared<Header::ContentType>(mime));
} }
Async::Promise<ssize_t> send(Code code) { Async::Promise<ssize_t> send(Code code) {
...@@ -220,8 +228,9 @@ public: ...@@ -220,8 +228,9 @@ public:
return w.send(); return w.send();
} }
/* @Revisit: not sure about the name yet */
ResponseWriter ResponseWriter
writer(Code code, size_t size = DefaultStreamSize) { beginWrite(Code code = Code::Ok, size_t size = DefaultStreamSize) {
code_ = code; code_ = code;
return ResponseWriter(std::move(*this), size, peer_); return ResponseWriter(std::move(*this), size, peer_);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment