| 134 | } |
| 135 | |
| 136 | HttpServer::MicroHttpdResult HttpServer::callback(void *cls, MHD_Connection *connection, const char *url, const char *method, const char *version, |
| 137 | const char *upload_data, size_t *upload_data_size, void **con_cls) { |
| 138 | (void)version; |
| 139 | if (*con_cls == NULL) { |
| 140 | struct mhd_coninfo *client_connection = new mhd_coninfo; |
| 141 | client_connection->connection = connection; |
| 142 | client_connection->server = static_cast<HttpServer *>(cls); |
| 143 | *con_cls = client_connection; |
| 144 | return MHD_YES; |
| 145 | } |
| 146 | struct mhd_coninfo *client_connection = static_cast<struct mhd_coninfo *>(*con_cls); |
| 147 | |
| 148 | if (string("POST") == method) { |
| 149 | if (*upload_data_size != 0) { |
| 150 | client_connection->request.write(upload_data, *upload_data_size); |
| 151 | *upload_data_size = 0; |
| 152 | return MHD_YES; |
| 153 | } else { |
| 154 | string response; |
| 155 | IClientConnectionHandler *handler = client_connection->server->GetHandler(string(url)); |
| 156 | if (handler == NULL) { |
| 157 | client_connection->code = MHD_HTTP_INTERNAL_SERVER_ERROR; |
| 158 | client_connection->server->SendResponse("No client connection handler found", client_connection); |
| 159 | } else { |
| 160 | client_connection->code = MHD_HTTP_OK; |
| 161 | handler->HandleRequest(client_connection->request.str(), response); |
| 162 | client_connection->server->SendResponse(response, client_connection); |
| 163 | } |
| 164 | } |
| 165 | } else if (string("OPTIONS") == method) { |
| 166 | client_connection->code = MHD_HTTP_OK; |
| 167 | client_connection->server->SendOptionsResponse(client_connection); |
| 168 | } else { |
| 169 | client_connection->code = MHD_HTTP_METHOD_NOT_ALLOWED; |
| 170 | client_connection->server->SendResponse("Not allowed HTTP Method", client_connection); |
| 171 | } |
| 172 | |
| 173 | if (client_connection != nullptr) { |
| 174 | delete client_connection; |
| 175 | } |
| 176 | *con_cls = NULL; |
| 177 | |
| 178 | return MHD_YES; |
| 179 | } |
nothing calls this directly
no test coverage detected