我尝试结合Poco和boost :: iostreams :: filtering_stream,发现两个问题:
Poco::Net::HTTPChunkedStreamBuf::underflow
仅在会话关闭后才返回EOF。boost::iostreams::detail:indirect_streambuf::underflow
:返回值基于成功读取的符号数。 Poco::Net::HTTPChunkedStreamBuf::underflow
是否必须在会话关闭后重复返回EOF或在这种情况下返回值未定义?
仅从boost::iostreams::detail::indirect_streambuf::underflow
读取0个符号还是从streambuf
返回EOF还是应该检查sgetc()
的EOF并在这种情况下返回EOF是正确的?
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";
}
};
如果运行此命令,我将冻结:
curl 'http://localhost:5959/' -H 'Transfer-Encoding: chunked' -d '1234'
我发现,如果过滤流的缓冲区大小为0,则不会冻结。