| 35 | } |
| 36 | |
| 37 | bool 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 | |
| 76 | bool WebsocketServlet_impl::onPing(unsigned long long, bool) |
| 77 | { |
nothing calls this directly
no test coverage detected