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

Method doPost

lib_acl_cpp/samples/http/webSocketServlet/WebsocketServlet_impl.cpp:37–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35}
36
37bool WebsocketServlet_impl::doPost(acl::HttpServletRequest& req,
38 acl::HttpServletResponse& res)
39{
40 res.setContentType("text/html; charset=utf-8") // ������Ӧ�ַ���
41 .setContentEncoding(false) // �����Ƿ�ѹ������
42 .setChunkedTransferEncoding(true); // ���� chunk ���䷽ʽ
43
44 const char* ip = req.getLocalAddr();
45 if (ip == NULL || *ip == 0) {
46 logger_error("getLocalAddr error");
47 return false;
48 }
49 unsigned short port = req.getLocalPort();
50 if (port == 0) {
51 logger_error("getLocalPort error");
52 return false;
53 }
54
55 acl::string local_addr;
56 local_addr << ip << ":" << port;
57
58 printf("getLocalAddr: %s\r\n", local_addr.c_str());
59
60 acl::string html_file;
61 html_file << "www/upload.html";
62 acl::string buf;
63 if (acl::ifstream::load(html_file, &buf) == false) {
64 logger_error("load %s error %s",
65 html_file.c_str(), acl::last_serror());
66 return doError(req, res);
67 }
68
69 buf << "<script>g_url='ws://" << local_addr << "/'</script>";
70
71 // ���� http ��Ӧ�壬��Ϊ������ chunk ����ģʽ��������Ҫ�����һ��
72 // res.write ������������Ϊ 0 �Ա�ʾ chunk �������ݽ���
73 return res.write(buf) && res.write(NULL, 0);
74}
75
76bool WebsocketServlet_impl::onPing(unsigned long long, bool)
77{

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