src/HTTPServer.cpp
branchv_0
changeset 4 37a86904145c
parent 3 1184f3de5533
child 5 121981e6bd54
--- a/src/HTTPServer.cpp	Fri Apr 08 22:38:45 2022 +0200
+++ b/src/HTTPServer.cpp	Sat Apr 09 17:50:46 2022 +0200
@@ -54,17 +54,22 @@
 		// TODO: return also HTTP headers
 		if (impl->requestHandler) {
 			HTTPServer::Request request;
+			request.method = method;
+			request.url = url;
+			// FIXME: request.body = ...
+			// FIXME: multiple calls for one request
 			const HTTPServer::Response response = impl->requestHandler->handle(request);
 			struct MHD_Response* mhdResponse = MHD_create_response_from_buffer(response.body.size(), (void*) response.body.c_str(), MHD_RESPMEM_MUST_COPY);
+			for (Header h : response.header) MHD_add_response_header(mhdResponse, h.name.c_str(), h.value.c_str());
 			MHD_queue_response(connection, response.code, mhdResponse);
 			MHD_destroy_response(mhdResponse);
 			return MHD_YES;
 		} else {
 			// there might be a point in time when the HTTP server is started and HTTP handler is not set
 			// TODO: just return MHD_NO?
-			static const char body[] = "<h1>HTTP 404: Not found</h1>";
+			static const char body[] = "<h1>HTTP 503: Service Unavailable</h1><p>not fully started yet</p>";
 			struct MHD_Response* mhdResponse = MHD_create_response_from_buffer(sizeof (body), (void*) body, MHD_RESPMEM_PERSISTENT);
-			MHD_queue_response(connection, 404, mhdResponse);
+			MHD_queue_response(connection, 503, mhdResponse);
 			MHD_destroy_response(mhdResponse);
 			return MHD_YES;
 		}