mirror of
https://gitee.com/an-tao/drogon.git
synced 2024-12-02 03:38:03 +08:00
adjust log out
This commit is contained in:
parent
2e80c2b132
commit
aba7182851
@ -28,6 +28,7 @@ namespace drogon
|
||||
void readSendFile(const std::string& filePath,const HttpRequest& req, HttpResponse* resp);
|
||||
#ifdef USE_UUID
|
||||
//if uuid package found,we can use a uuid string as session id;
|
||||
//set _sessionTimeout=0 to disable location session control based on cookies;
|
||||
uint _sessionTimeout=0;
|
||||
#endif
|
||||
bool _enableLastModify=true;
|
||||
|
@ -65,19 +65,20 @@ public:
|
||||
enum Version {
|
||||
kHttp10, kHttp11
|
||||
};
|
||||
|
||||
explicit HttpResponse(bool close)
|
||||
/*
|
||||
explicit HttpResponse()
|
||||
: statusCode_(kUnknown),
|
||||
closeConnection_(close),
|
||||
left_body_length_(0),
|
||||
current_chunk_length_(0)
|
||||
{
|
||||
}
|
||||
|
||||
explicit HttpResponse()
|
||||
*/
|
||||
explicit HttpResponse()
|
||||
: statusCode_(kUnknown),
|
||||
closeConnection_(false),
|
||||
left_body_length_(0)
|
||||
left_body_length_(0),
|
||||
current_chunk_length_(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -30,27 +30,27 @@ void HttpAppFramework::run()
|
||||
|
||||
void HttpAppFramework::onAsyncRequest(const HttpRequest& req,std::function<void (HttpResponse &)>callback)
|
||||
{
|
||||
std::cout << "Headers " << req.methodString() << " " << req.path() << std::endl;
|
||||
LOG_TRACE << "Headers " << req.methodString() << " " << req.path();
|
||||
|
||||
#if 1
|
||||
const std::map<std::string, std::string>& headers = req.headers();
|
||||
for (std::map<std::string, std::string>::const_iterator it = headers.begin();
|
||||
it != headers.end();
|
||||
++it) {
|
||||
std::cout << it->first << ": " << it->second << std::endl;
|
||||
LOG_TRACE << it->first << ": " << it->second;
|
||||
}
|
||||
|
||||
std::cout<<"cookies:"<<std::endl;
|
||||
LOG_TRACE<<"cookies:";
|
||||
auto cookies = req.cookies();
|
||||
for(auto it=cookies.begin();it!=cookies.end();++it)
|
||||
{
|
||||
std::cout<<it->first<<"="<<it->second<<std::endl;
|
||||
LOG_TRACE<<it->first<<"="<<it->second;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
LOG_INFO << "http path=" << req.path();
|
||||
LOG_INFO << "query: " << req.query() ;
|
||||
LOG_TRACE << "http path=" << req.path();
|
||||
LOG_TRACE << "query: " << req.query() ;
|
||||
#ifdef USE_UUID
|
||||
std::string session_id=req.getCookie("JSESSIONID");
|
||||
bool needSetJsessionid=false;
|
||||
@ -79,7 +79,7 @@ void HttpAppFramework::onAsyncRequest(const HttpRequest& req,std::function<void
|
||||
if(_fileTypeSet.find(filetype) != _fileTypeSet.end()) {
|
||||
LOG_INFO << "file query!";
|
||||
std::string filePath = _rootPath + path;
|
||||
HttpResponse resp(true);
|
||||
HttpResponse resp;
|
||||
#ifdef USE_UUID
|
||||
if(needSetJsessionid)
|
||||
resp.addCookie("JSESSIONID",session_id);
|
||||
@ -154,7 +154,7 @@ void HttpAppFramework::onAsyncRequest(const HttpRequest& req,std::function<void
|
||||
|
||||
LOG_ERROR<<"can't find controller "<<ctrlName;
|
||||
*/
|
||||
HttpResponse resp(true);
|
||||
HttpResponse resp;
|
||||
|
||||
resp.setStatusCode(HttpResponse::k404NotFound);
|
||||
//resp.setCloseConnection(true);
|
||||
@ -182,10 +182,10 @@ void HttpAppFramework::readSendFile(const std::string& filePath,const HttpReques
|
||||
if(_enableLastModify)
|
||||
{
|
||||
struct stat fileStat;
|
||||
LOG_DEBUG<<"enabled LastModify";
|
||||
LOG_TRACE<<"enabled LastModify";
|
||||
if(stat(filePath.c_str(),&fileStat)>=0)
|
||||
{
|
||||
std::cout<<"last modify time:"<<fileStat.st_mtime<<std::endl;
|
||||
LOG_TRACE<<"last modify time:"<<fileStat.st_mtime;
|
||||
struct tm tm1;
|
||||
gmtime_r(&fileStat.st_mtime,&tm1);
|
||||
char timeBuf[64];
|
||||
|
@ -108,7 +108,7 @@ bool HttpContext::parseRequest(MsgBuffer *buf)
|
||||
{
|
||||
// empty line, end of header
|
||||
std::string len = request_.getHeader("Content-Length");
|
||||
LOG_INFO << "content len=" << len;
|
||||
LOG_TRACE << "content len=" << len;
|
||||
if (len != "")
|
||||
{
|
||||
request_.contentLen = atoi(len.c_str());
|
||||
@ -154,9 +154,9 @@ bool HttpContext::parseRequest(MsgBuffer *buf)
|
||||
if (request_.contentLen <= 0)
|
||||
{
|
||||
state_ = kGotAll;
|
||||
LOG_INFO << "post got all:len=" << request_.content_.length();
|
||||
LOG_TRACE << "post got all:len=" << request_.content_.length();
|
||||
//LOG_INFO<<"content:"<<request_.content_;
|
||||
LOG_INFO << "content(END)";
|
||||
LOG_TRACE << "content(END)";
|
||||
hasMore = false;
|
||||
}
|
||||
}
|
||||
@ -170,7 +170,7 @@ bool HttpContext::processResponseLine(const char *begin, const char *end)
|
||||
const char *space = std::find(start, end, ' ');
|
||||
if (space != end)
|
||||
{
|
||||
LOG_DEBUG << *(space - 1);
|
||||
LOG_TRACE << *(space - 1);
|
||||
if (*(space - 1) == '1')
|
||||
{
|
||||
response_.setVersion(HttpResponse::kHttp11);
|
||||
@ -191,7 +191,7 @@ bool HttpContext::processResponseLine(const char *begin, const char *end)
|
||||
{
|
||||
std::string status_code(start, space - start);
|
||||
std::string status_message(space + 1, end - space - 1);
|
||||
LOG_DEBUG << status_code << " " << status_message;
|
||||
LOG_TRACE << status_code << " " << status_message;
|
||||
switch (atoi(status_code.c_str()))
|
||||
{
|
||||
case 200:
|
||||
@ -225,11 +225,8 @@ bool HttpContext::parseResponse(MsgBuffer *buf)
|
||||
{
|
||||
bool ok = true;
|
||||
bool hasMore = true;
|
||||
// std::cout<<std::string(buf->peek(),buf->readableBytes())<<std::endl;
|
||||
//LOG_INFO<<"response message:"<<std::string(buf->peek(),buf->readableBytes());
|
||||
while (hasMore)
|
||||
{
|
||||
//LOG_DEBUG<<"res_state_: "<<(int)res_state_;
|
||||
if (res_state_ == HttpResponseParseState::kExpectResponseLine)
|
||||
{
|
||||
const char *crlf = buf->findCRLF();
|
||||
@ -322,9 +319,9 @@ bool HttpContext::parseResponse(MsgBuffer *buf)
|
||||
if (response_.left_body_length_ <= 0)
|
||||
{
|
||||
res_state_ = HttpResponseParseState::kGotAll;
|
||||
LOG_INFO << "post got all:len=" << response_.left_body_length_;
|
||||
LOG_TRACE << "post got all:len=" << response_.left_body_length_;
|
||||
//LOG_INFO<<"content:"<<request_.content_;
|
||||
LOG_INFO << "content(END)";
|
||||
LOG_TRACE << "content(END)";
|
||||
hasMore = false;
|
||||
}
|
||||
}
|
||||
@ -343,7 +340,7 @@ bool HttpContext::parseResponse(MsgBuffer *buf)
|
||||
std::string len(buf->peek(), crlf - buf->peek());
|
||||
char *end;
|
||||
response_.current_chunk_length_ = strtol(len.c_str(), &end, 16);
|
||||
LOG_DEBUG << "chun length : " << response_.current_chunk_length_;
|
||||
LOG_TRACE << "chun length : " << response_.current_chunk_length_;
|
||||
if (response_.current_chunk_length_ != 0)
|
||||
{
|
||||
res_state_ = HttpResponseParseState::kExpectChunkBody;
|
||||
|
@ -29,7 +29,7 @@ using namespace trantor;
|
||||
|
||||
static void defaultHttpAsyncCallback(const HttpRequest&, std::function<void( HttpResponse& resp)>callback)
|
||||
{
|
||||
HttpResponse resp(true);
|
||||
HttpResponse resp;
|
||||
resp.setStatusCode(HttpResponse::k404NotFound);
|
||||
resp.setCloseConnection(true);
|
||||
callback(resp);
|
||||
@ -89,14 +89,14 @@ void HttpServer::onMessage(const TcpConnectionPtr& conn,
|
||||
void HttpServer::onRequest(const TcpConnectionPtr& conn, const HttpRequest& req)
|
||||
{
|
||||
const std::string& connection = req.getHeader("Connection");
|
||||
bool close = connection == "close" ||
|
||||
bool _close = connection == "close" ||
|
||||
(req.getVersion() == HttpRequest::kHttp10 && connection != "Keep-Alive");
|
||||
|
||||
|
||||
|
||||
httpAsyncCallback_(req, [ = ](HttpResponse & response) {
|
||||
MsgBuffer buf;
|
||||
response.setCloseConnection(close);
|
||||
response.setCloseConnection(_close);
|
||||
response.appendToBuffer(&buf);
|
||||
conn->send(buf.peek(),buf.readableBytes());
|
||||
if (response.closeConnection()) {
|
||||
|
Loading…
Reference in New Issue
Block a user