summaryrefslogtreecommitdiffhomepage
path: root/http.c
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2020-05-01 15:43:07 +0200
committerAki <please@ignore.pl>2020-05-01 16:42:19 +0200
commit922bb99578b881065048102e03c73ff91c5ad30a (patch)
treed2033cf94f7330c194e53f91d8d4bf40d34370ca /http.c
parent03360ae6aa07289eac060870972d4ba246ca88d3 (diff)
downloadplop-922bb99578b881065048102e03c73ff91c5ad30a.zip
plop-922bb99578b881065048102e03c73ff91c5ad30a.tar.gz
plop-922bb99578b881065048102e03c73ff91c5ad30a.tar.bz2
Moved out http-related functionality out of main file
Diffstat (limited to 'http.c')
-rw-r--r--http.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/http.c b/http.c
new file mode 100644
index 0000000..706b982
--- /dev/null
+++ b/http.c
@@ -0,0 +1,27 @@
+#include "http.h"
+
+#include <stdio.h>
+
+const char * status_string[] = {
+ [STATUS_OK] = "200 OK",
+ [STATUS_BAD_REQUEST] = "400 Bad Request",
+ [STATUS_METHOD_NOT_ALLOWED] = "405 Method Not Allowed",
+ [STATUS_REQUEST_TIMEOUT] = "408 Request Timeout",
+ [STATUS_INTERNAL_SERVER_ERROR] = "500 Internal Server Error",
+ [STATUS_NOT_IMPLEMENTED] = "501 Not Implemented",
+ [STATUS_VERSION_NOT_SUPPORTED] = "505 Version Not Supported",
+};
+
+/// Sends a simple response only with a status to the client.
+/// \param fd File descriptor of the client socket
+/// \param status HTTP response status code
+/// \return Negative value if an error was encountered; numbers of bytes written otherwise
+int respond_only_status(const int fd, const enum status status)
+{
+ static const char * pattern =
+ "HTTP/1.1 %s\r\n"
+ "Connection: close\r\n"
+ "\r\n";
+
+ return dprintf(fd, pattern, status_string[status]);
+}