| 53 | } |
| 54 | |
| 55 | static void HttpResponse(void* user_data, const dmHttpServer::Request* request) |
| 56 | { |
| 57 | dmHttpServerTest* self = (dmHttpServerTest*) user_data; |
| 58 | self->m_Major = request->m_Major; |
| 59 | self->m_Minor = request->m_Minor; |
| 60 | self->m_RequestMethod = request->m_Method; |
| 61 | self->m_Resource = request->m_Resource; |
| 62 | |
| 63 | if (strstr(self->m_Resource.c_str(), "/respond_with_n/")) |
| 64 | { |
| 65 | int n; |
| 66 | sscanf(self->m_Resource.c_str(), "/respond_with_n/%d", &n); |
| 67 | |
| 68 | std::string buf; |
| 69 | for (int i = 0; i < n; ++i) |
| 70 | { |
| 71 | int c = (n + i*97) % ('z' - 'a'); |
| 72 | char s[2] = { (char)('a' + (char)c), '\0' }; |
| 73 | buf.append(s, 1); |
| 74 | } |
| 75 | |
| 76 | int sent_bytes = 0; |
| 77 | while (n > 0) |
| 78 | { |
| 79 | int n_to_send = dmMath::Min(17, n); |
| 80 | dmHttpServer::Send(request, buf.c_str() + sent_bytes, n_to_send); |
| 81 | n -= n_to_send; |
| 82 | sent_bytes += n_to_send; |
| 83 | } |
| 84 | } |
| 85 | else if (strstr(self->m_Resource.c_str(), "/mul/")) |
| 86 | { |
| 87 | int a,b; |
| 88 | sscanf(self->m_Resource.c_str(), "/mul/%d/%d", &a,&b); |
| 89 | int c = a + b; |
| 90 | char buf[16]; |
| 91 | dmSnPrintf(buf, sizeof(buf), "%d", c); |
| 92 | dmHttpServer::Send(request, buf, strlen(buf)); |
| 93 | } |
| 94 | else if (strstr(self->m_Resource.c_str(), "/test_html")) |
| 95 | { |
| 96 | const char* html = "<html></html>"; |
| 97 | dmHttpServer::SendAttribute(request, "Content-Type", "text/html"); |
| 98 | dmHttpServer::Send(request, html, strlen(html)); |
| 99 | } |
| 100 | else if (strstr(self->m_Resource.c_str(), "/quit")) |
| 101 | { |
| 102 | dmAtomicStore32(&self->m_Quit, 1); |
| 103 | } |
| 104 | else if (strstr(self->m_Resource.c_str(), "/post")) |
| 105 | { |
| 106 | uint32_t total = 0; |
| 107 | |
| 108 | while (total < request->m_ContentLength) |
| 109 | { |
| 110 | // NOTE: Small buffer here to test buffer boundaries in dmHttpServer::Receive |
| 111 | char recv_buf[17]; |
| 112 | uint32_t recv_bytes = 0; |
nothing calls this directly
no test coverage detected