This commit is contained in:
Gregory Burd 2024-05-01 21:34:39 -04:00
parent 558ff4d606
commit 39fbcf7dad
2 changed files with 5 additions and 9 deletions

View file

@ -1,6 +1,6 @@
#include "database.hh" #include "database.hh"
#include <seastar/util/short_streams.hh>
#include "noidb.hh" #include "noidb.hh"
seastar::future<bool> Database::stop() { seastar::future<bool> Database::stop() {
@ -18,12 +18,8 @@ future<bool> Database::put(const sstring& key, sstring& val) {
co_return true; co_return true;
} }
future<bool> Database::post(const sstring& key, input_stream<char>* stream) { future<bool> Database::post(const sstring& key, sstring& val, size_t bytes) {
sstring val; lg.info("post: {} -> {} {}", key, bytes, val);
while (auto buf = co_await stream->read()) {
val.append(buf.get(), buf.size());
}
lg.info("post: {} -> {}", key, val);
co_return true; co_return true;
} }
@ -59,7 +55,7 @@ PostHandler::PostHandler(Database& db)
future<std::unique_ptr<http::reply>> future<std::unique_ptr<http::reply>>
PostHandler::handle(const sstring& path, std::unique_ptr<http::request> req, std::unique_ptr<http::reply> rep) { PostHandler::handle(const sstring& path, std::unique_ptr<http::request> req, std::unique_ptr<http::reply> rep) {
sstring rest = req->param.get_decoded_param("path"); sstring rest = req->param.get_decoded_param("path");
rep->write_body("json", json::stream_object(co_await db.post(rest, req->content_stream))); rep->write_body("json", json::stream_object(co_await db.post(rest, req->content, req->content_length)));
co_return std::move(rep); co_return std::move(rep);
} }

View file

@ -13,7 +13,7 @@ public:
future<bool> stop(); future<bool> stop();
future<sstring> get(const sstring& key); future<sstring> get(const sstring& key);
future<bool> put(const sstring& key, sstring& val); future<bool> put(const sstring& key, sstring& val);
future<bool> post(const sstring& key, input_stream<char>* val); future<bool> post(const sstring& key, sstring& val, size_t bytes);
future<bool> del(const sstring& key); future<bool> del(const sstring& key);
}; };