MCPcopy Create free account
hub / github.com/acl-dev/acl / doPost

Method doPost

lib_acl_cpp/samples/websocket/upload_server/http_servlet.cpp:53–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51}
52
53bool http_servlet::doPost(acl::HttpServletRequest& req,
54 acl::HttpServletResponse& res)
55{
56 res.setContentType("text/html; charset=utf-8") // ������Ӧ�ַ���
57 .setContentEncoding(true) // �����Ƿ�ѹ������
58 .setChunkedTransferEncoding(true); // ���� chunk ���䷽ʽ
59
60 const char* ip = req.getLocalAddr();
61 if (ip == NULL || *ip == 0)
62 {
63 logger_error("getLocalAddr error");
64 return false;
65 }
66 unsigned short port = req.getLocalPort();
67 if (port == 0)
68 {
69 logger_error("getLocalPort error");
70 return false;
71 }
72
73 acl::string local_addr;
74 local_addr << ip << ":" << port;
75
76 printf("getLocalAddr: %s\r\n", local_addr.c_str());
77
78 acl::string html_file;
79 html_file << var_cfg_html_path << "/upload.html";
80 acl::string buf;
81 if (acl::ifstream::load(html_file, &buf) == false)
82 {
83 logger_error("load %s error %s",
84 html_file.c_str(), acl::last_serror());
85 return doError(req, res);
86 }
87
88 buf << "<script>g_url='ws://" << local_addr << "/'</script>";
89
90 // ���� http ��Ӧ�壬��Ϊ������ chunk ����ģʽ��������Ҫ�����һ��
91 // res.write ������������Ϊ 0 �Ա�ʾ chunk �������ݽ���
92 return res.write(buf) && res.write(NULL, 0);
93}
94
95bool http_servlet::doPing(acl::websocket& in, acl::websocket& out)
96{

Callers

nothing calls this directly

Calls 7

setContentEncodingMethod · 0.80
setContentTypeMethod · 0.80
getLocalAddrMethod · 0.80
getLocalPortMethod · 0.80
last_serrorFunction · 0.50
c_strMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected