57 request.method = method; |
57 request.method = method; |
58 request.url = url; |
58 request.url = url; |
59 |
59 |
60 // TODO: return also client IP address etc. |
60 // TODO: return also client IP address etc. |
61 // const MHD_ConnectionInfo* connetionInfo = MHD_get_connection_info(connection, MHD_ConnectionInfoType::MHD_CONNECTION_INFO_CLIENT_ADDRESS); |
61 // const MHD_ConnectionInfo* connetionInfo = MHD_get_connection_info(connection, MHD_ConnectionInfoType::MHD_CONNECTION_INFO_CLIENT_ADDRESS); |
62 |
62 |
63 // FIXME: request.body = ... |
63 // FIXME: request.body = ... |
64 // FIXME: multiple calls for one request |
64 // FIXME: multiple calls for one request |
|
65 // FIXME: POST parameters |
|
66 |
|
67 // HTTP headers: |
|
68 MHD_get_connection_values(connection, MHD_ValueKind::MHD_HEADER_KIND, [](void* cls, MHD_ValueKind kind, const char* key, const char* value) { |
|
69 (static_cast<std::vector<AVP>*> (cls))->push_back({key, value}); |
|
70 return MHD_YES; |
|
71 }, &request.header); |
|
72 |
|
73 // GET parameters: |
|
74 MHD_get_connection_values(connection, MHD_ValueKind::MHD_GET_ARGUMENT_KIND, [](void* cls, MHD_ValueKind kind, const char* key, const char* value) { |
|
75 (static_cast<std::vector<AVP>*> (cls))->push_back({key, value}); |
|
76 return MHD_YES; |
|
77 }, &request.getParameter); |
|
78 |
|
79 // COOKIE parameters: |
|
80 MHD_get_connection_values(connection, MHD_ValueKind::MHD_COOKIE_KIND, [](void* cls, MHD_ValueKind kind, const char* key, const char* value) { |
|
81 (static_cast<std::vector<AVP>*> (cls))->push_back({key, value}); |
|
82 return MHD_YES; |
|
83 }, &request.cookie); |
|
84 |
65 const HTTPServer::Response response = impl->requestHandler->handle(request); |
85 const HTTPServer::Response response = impl->requestHandler->handle(request); |
66 struct MHD_Response* mhdResponse = MHD_create_response_from_buffer(response.body.size(), (void*) response.body.c_str(), MHD_RESPMEM_MUST_COPY); |
86 struct MHD_Response* mhdResponse = MHD_create_response_from_buffer(response.body.size(), (void*) response.body.c_str(), MHD_RESPMEM_MUST_COPY); |
67 for (Header h : response.header) MHD_add_response_header(mhdResponse, h.name.c_str(), h.value.c_str()); |
87 for (AVP h : response.header) MHD_add_response_header(mhdResponse, h.name.c_str(), h.value.c_str()); |
|
88 // FIXME: cookies: for (AVP c : response.cookie) ... |
68 MHD_queue_response(connection, response.code, mhdResponse); |
89 MHD_queue_response(connection, response.code, mhdResponse); |
69 MHD_destroy_response(mhdResponse); |
90 MHD_destroy_response(mhdResponse); |
70 return MHD_YES; |
91 return MHD_YES; |
71 } else { |
92 } else { |
72 // there might be a point in time when the HTTP server is started and HTTP handler is not set |
93 // there might be a point in time when the HTTP server is started and HTTP handler is not set |