I try to combine Poco and boost::iostreams::filtering_stream and I found two problems:
Poco::Net::HTTPChunkedStreamBuf::underflow
returns EOF only once after session was closed.boost::iostreams::detail:indirect_streambuf::underflow
: return value is based on number of successfully read symbols.
Does Poco::Net::HTTPChunkedStreamBuf::underflow
must return EOF repeatedly after session close or return value in that case is undefined?
Is it correct to return EOF from boost::iostreams::detail::indirect_streambuf::underflow
only if it reads 0 symbols from streambuf
or it should check sgetc()
for EOF and return EOF in that case?
class Handler : public HTTPRequestHandler {
public:
void handleRequest(HTTPServerRequest &request,
HTTPServerResponse &response) {
response.setKeepAlive(request.getKeepAlive());
response.setChunkedTransferEncoding(true);
auto &stream = request.stream();
boost::iostreams::filtering_stream<boost::iostreams::input> teeStream;
teeStream.push(boost::iostreams::tee(std::cout));
teeStream.push(stream);
std::string payload;
teeStream >> payload;
std::cerr << payload;
std::cerr << "handleRequest end" << std::endl;
auto &ostr = response.send();
ostr << "12345";
}
};
I get freeze if i run this:
curl 'http://localhost:5959/' -H 'Transfer-Encoding: chunked' -d '1234'
I found that if the buffer size of the filtering stream is 0 then there is no freezes.