acl/app/wizard/tmpl/http/http_servlet.cpp

91 lines
2.3 KiB
C++
Raw Normal View History

2014-11-19 00:25:21 +08:00
#include "stdafx.h"
#include "http_servlet.h"
http_servlet::http_servlet(acl::socket_stream* stream, acl::session* session)
: acl::HttpServlet(stream, session)
2014-11-19 00:25:21 +08:00
{
}
http_servlet::~http_servlet(void)
{
}
bool http_servlet::doError(acl::HttpServletRequest&,
2014-11-19 00:25:21 +08:00
acl::HttpServletResponse& res)
{
res.setStatus(400);
res.setContentType("text/xml; charset=utf-8");
// <20><><EFBFBD><EFBFBD> http <20><>Ӧ<EFBFBD><D3A6>
acl::string buf;
buf.format("<root error='some error happened!' />\r\n");
res.write(buf);
res.write(NULL, 0);
return false;
}
bool http_servlet::doOther(acl::HttpServletRequest&,
acl::HttpServletResponse& res, const char* method)
2014-11-19 00:25:21 +08:00
{
res.setStatus(400);
res.setContentType("text/xml; charset=utf-8");
2014-11-19 00:25:21 +08:00
// <20><><EFBFBD><EFBFBD> http <20><>Ӧ<EFBFBD><D3A6>
acl::string buf;
buf.format("<root error='unkown request method %s' />\r\n", method);
res.write(buf);
res.write(NULL, 0);
2014-11-19 00:25:21 +08:00
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)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ http session <20><><EFBFBD>ƣ<EFBFBD><C6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>֤
// <20><> master_service.cpp <20>ĺ<EFBFBD><C4BA><EFBFBD> thread_on_read <20><><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>
// memcached <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/*
const char* sid = req.getSession().getAttribute("sid");
if (*sid == 0)
req.getSession().setAttribute("sid", "xxxxxx");
sid = req.getSession().getAttribute("sid");
*/
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫȡ<D2AA><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> cookie <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
/*
$<GET_COOKIES>
*/
res.setContentType("text/xml; charset=utf-8") // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
.setKeepAlive(req.isKeepAlive()) // <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ񱣳ֳ<F1B1A3B3><D6B3><EFBFBD><EFBFBD><EFBFBD>
2015-08-22 18:05:46 +08:00
.setContentEncoding(true) // <20>Զ<EFBFBD>֧<EFBFBD><D6A7>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
.setChunkedTransferEncoding(true); // <20><><EFBFBD><EFBFBD> chunk <20><><EFBFBD>ʽ
const char* param1 = req.getParameter("name1");
const char* param2 = req.getParameter("name2");
// <20><><EFBFBD><EFBFBD> xml <20><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2015-12-20 21:24:28 +08:00
acl::xml1 body;
2014-11-19 00:25:21 +08:00
body.get_root()
.add_child("root", true)
.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);
// <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>
return res.write(buf) && res.write(NULL, 0);
2014-11-19 00:25:21 +08:00
}