add http pipelining support
This commit is contained in:
parent
a17b950b21
commit
4d11399d48
|
|
@ -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>;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -141,12 +141,12 @@ ssize_t HttpSession::onRecvHeader(const char *header, size_t len) {
|
|||
_parser.clear();
|
||||
|
||||
// 后续是header
|
||||
setContentLen(0);
|
||||
//setContentLen(0);
|
||||
return false;
|
||||
};
|
||||
|
||||
// 声明后续都是body;Http 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); });
|
||||
|
|
|
|||
Loading…
Reference in New Issue