add http pipelining support

This commit is contained in:
xiongguangjie 2023-12-22 19:54:09 +08:00
parent a17b950b21
commit 4d11399d48
3 changed files with 22 additions and 3 deletions

View File

@ -181,6 +181,10 @@ int HttpFileBody::sendFile(int fd) {
#endif
}
bool HttpFileBody::isMem(){
return false;
}
class BufferMmap : public Buffer {
public:
using Ptr = std::shared_ptr<BufferMmap>;

View File

@ -44,6 +44,12 @@ public:
*/
virtual toolkit::Buffer::Ptr readData(size_t size) { return nullptr;};
/**
*
* @return true
*/
virtual bool isMem(){return true;};
/**
* size
* @param size
@ -121,6 +127,7 @@ public:
int64_t remainSize() override;
toolkit::Buffer::Ptr readData(size_t size) override;
int sendFile(int fd) override;
bool isMem() override;
private:
int64_t _read_to = 0;

View File

@ -141,12 +141,12 @@ ssize_t HttpSession::onRecvHeader(const char *header, size_t len) {
_parser.clear();
// 后续是header
setContentLen(0);
//setContentLen(0);
return false;
};
// 声明后续都是bodyHttp body在本对象缓冲不通过HttpRequestSplitter保存
return -1;
return content_len;
}
void HttpSession::onRecvContent(const char *data, size_t len) {
@ -687,6 +687,14 @@ void HttpSession::sendResponse(int code,
setSocketFlags();
}
if(body->isMem()){
send(body->readData(body->remainSize()));
if(bClose){
shutdown(SockException(Err_shutdown, StrPrinter << "close connection after send http body"));
}
return;
}
// 发送http body
AsyncSenderData::Ptr data = std::make_shared<AsyncSenderData>(static_pointer_cast<HttpSession>(shared_from_this()), body, bClose);
getSock()->setOnFlush([data]() { return AsyncSender::onSocketFlushed(data); });