2019-07-28 10:31:56 +08:00
|
|
|
|
#include "stdafx.h"
|
2015-06-03 11:19:13 +08:00
|
|
|
|
#include "http_servlet.h"
|
|
|
|
|
|
|
|
|
|
http_servlet::http_servlet(acl::redis_client_cluster& cluster, size_t max_conns)
|
|
|
|
|
{
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD> session <20>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD>
|
2015-06-03 11:19:13 +08:00
|
|
|
|
session_ = new acl::redis_session(cluster, max_conns);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
http_servlet::~http_servlet(void)
|
|
|
|
|
{
|
|
|
|
|
delete session_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool http_servlet::doUnknown(acl::HttpServletRequest&,
|
|
|
|
|
acl::HttpServletResponse& res)
|
|
|
|
|
{
|
|
|
|
|
res.setStatus(400);
|
|
|
|
|
res.setContentType("text/html; charset=");
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD> http <20><>Ӧͷ
|
2015-06-03 11:19:13 +08:00
|
|
|
|
if (res.sendHeader() == false)
|
|
|
|
|
return false;
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD> http <20><>Ӧ<EFBFBD><D3A6>
|
2015-06-03 11:19:13 +08:00
|
|
|
|
acl::string buf("<root error='unkown request method' />\r\n");
|
|
|
|
|
(void) res.getOutputStream().write(buf);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool http_servlet::doGet(acl::HttpServletRequest& req,
|
|
|
|
|
acl::HttpServletResponse& res)
|
|
|
|
|
{
|
|
|
|
|
return doPost(req, res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool http_servlet::doPost(acl::HttpServletRequest& req,
|
|
|
|
|
acl::HttpServletResponse& res)
|
|
|
|
|
{
|
2015-08-18 20:58:56 +08:00
|
|
|
|
#if 0
|
2015-06-03 22:59:21 +08:00
|
|
|
|
const char* session_name = req.getSession().getAttribute("session_name");
|
|
|
|
|
if (*session_name == 0)
|
2015-06-03 11:19:13 +08:00
|
|
|
|
{
|
|
|
|
|
req.getSession().setAttribute("session_name", "name");
|
|
|
|
|
req.getSession().setMaxAge(100);
|
|
|
|
|
}
|
|
|
|
|
session_name = req.getSession().getAttribute("session_name");
|
|
|
|
|
|
2015-06-03 22:59:21 +08:00
|
|
|
|
const char* session_user = req.getSession().getAttribute("session_user");
|
|
|
|
|
if (*session_user == 0)
|
2015-06-03 11:19:13 +08:00
|
|
|
|
req.getSession().setAttribute("session_user", "user");
|
|
|
|
|
session_user = req.getSession().getAttribute("session_user");
|
2015-08-18 20:58:56 +08:00
|
|
|
|
#else
|
|
|
|
|
const char* session_name = "name", *session_user = "user";
|
|
|
|
|
#endif
|
2015-06-03 11:19:13 +08:00
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> cookie
|
2015-06-03 11:19:13 +08:00
|
|
|
|
const char* cookie_name = req.getCookieValue("cookie_name");
|
|
|
|
|
|
|
|
|
|
bool keep_alive = req.isKeepAlive();
|
|
|
|
|
|
|
|
|
|
const char* param1 = req.getParameter("name1");
|
|
|
|
|
const char* param2 = req.getParameter("name2");
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD> xml <20><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2016-07-20 21:09:46 +08:00
|
|
|
|
acl::xml1 body;
|
2015-06-03 11:19:13 +08:00
|
|
|
|
body.get_root()
|
|
|
|
|
.add_child("root", true)
|
|
|
|
|
.add_child("session", true)
|
|
|
|
|
.add_child("session_name", true)
|
|
|
|
|
.set_text(session_name)
|
|
|
|
|
.get_parent()
|
|
|
|
|
.add_child("session_user", true)
|
|
|
|
|
.set_text(session_user)
|
|
|
|
|
.get_parent()
|
|
|
|
|
.get_parent()
|
|
|
|
|
.add_child("cookie", true)
|
|
|
|
|
.add_child("cookie_name", true)
|
|
|
|
|
.set_text(cookie_name ? cookie_name : "")
|
|
|
|
|
.get_parent()
|
|
|
|
|
.get_parent()
|
|
|
|
|
.add_child("params", true)
|
|
|
|
|
.add_child("param", true)
|
|
|
|
|
.add_attr("name1", param1 ? param1 : "null")
|
|
|
|
|
.get_parent()
|
|
|
|
|
.add_child("param", true)
|
|
|
|
|
.add_attr("name2", param2 ? param2 : "null");
|
|
|
|
|
acl::string buf;
|
|
|
|
|
body.build_xml(buf);
|
|
|
|
|
|
|
|
|
|
#if 0
|
2019-07-28 10:31:56 +08:00
|
|
|
|
res.setContentType("text/xml; charset=utf-8") // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|
|
|
|
.setKeepAlive(keep_alive) // <20><><EFBFBD><EFBFBD><EFBFBD>Ƿֳ<F1B1A3B3><D6B3><EFBFBD><EFBFBD><EFBFBD>
|
2015-06-03 11:19:13 +08:00
|
|
|
|
//.setContentLength(buf.length());
|
|
|
|
|
#else
|
2019-07-28 10:31:56 +08:00
|
|
|
|
res.setContentType("text/xml; charset=utf-8") // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|
|
|
|
.setKeepAlive(keep_alive) // <20><><EFBFBD><EFBFBD><EFBFBD>Ƿֳ<F1B1A3B3><D6B3><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
.setContentEncoding(true) // <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
.setChunkedTransferEncoding(true); // <20><><EFBFBD><EFBFBD> chunk <20><><EFBFBD>䷽ʽ
|
2015-06-03 11:19:13 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
//logger("access http://%s%s", req.getRemoteAddr(), req.getRequestUri());
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD> http <20><>Ӧ<EFBFBD>壬<EFBFBD><E5A3AC>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD> chunk <20><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
|
|
|
|
// res.write <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ 0 <20>Ա<EFBFBD>ʾ chunk <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD>
|
2015-08-18 20:58:56 +08:00
|
|
|
|
return res.write(buf) && res.write(NULL, 0);
|
2015-06-03 11:19:13 +08:00
|
|
|
|
}
|