From 8cb5b78807e14bc3725bb5bc372ab8bee516e392 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 28 Feb 2019 13:01:25 -0800 Subject: [PATCH] ircd::resource: Ignore empty chunk from user by default unless explicit. --- include/ircd/resource/response.h | 2 +- ircd/resource.cc | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/ircd/resource/response.h b/include/ircd/resource/response.h index d01dcef84..d7aad00f6 100644 --- a/include/ircd/resource/response.h +++ b/include/ircd/resource/response.h @@ -41,7 +41,7 @@ struct ircd::resource::response::chunked client *c {nullptr}; unique_buffer buf; - size_t write(const const_buffer &chunk); + size_t write(const const_buffer &chunk, const bool &ignore_empty = true); const_buffer flush(const const_buffer &); bool finish(); diff --git a/ircd/resource.cc b/ircd/resource.cc index 2d8255146..ef9ed1ed0 100644 --- a/ircd/resource.cc +++ b/ircd/resource.cc @@ -862,7 +862,7 @@ ircd::resource::response::chunked::finish() if(!c) return false; - write(const_buffer{}); + write(const_buffer{}, false); c = nullptr; return true; } @@ -879,7 +879,8 @@ ircd::resource::response::chunked::flush(const const_buffer &buf) } size_t -ircd::resource::response::chunked::write(const const_buffer &chunk) +ircd::resource::response::chunked::write(const const_buffer &chunk, + const bool &ignore_empty) try { size_t ret{0}; @@ -887,6 +888,9 @@ try if(!c) return ret; + if(ignore_empty && empty(chunk)) + return ret; + //TODO: bring iov from net::socket -> net::write_() -> client::write_() char headbuf[32]; ret += c->write_all(http::writechunk(headbuf, size(chunk)));