From 200178c77b5a0fa00827250840481e11fa93bfaa Mon Sep 17 00:00:00 2001 From: Ian C Date: Sat, 7 Dec 2024 19:28:43 +0000 Subject: Updates to POST logging. Add MacOS debug dir to gitignore. --- .gitignore | 2 ++ httpserve.c | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index af7d53d..97beab7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ httpserve +core +httpserve.dSYM diff --git a/httpserve.c b/httpserve.c index 98045ad..5cbf387 100644 --- a/httpserve.c +++ b/httpserve.c @@ -525,19 +525,25 @@ static void *ThreadCode(void *p) { int file = -1; - printf("Got body of %lu bytes\n", - (unsigned long)content_len); - if (!StrMatch(filename, "/") && (file = open(filename, - O_WRONLY|O_CREAT|O_EXCL)) != -1 && + O_WRONLY|O_CREAT|O_EXCL, + 0664)) != -1 && write(file, contents, content_len) == content_len) { + printf("Wrote %lu bytes to '%s'\n", + (unsigned long)content_len, filename); + GenerateStatus(args->fd, 200, "OK", protocol); } else { + if (file == -1) + { + perror("open"); + } + GenerateStatus(args->fd, 500, "Failed to write contents", protocol); } @@ -568,7 +574,10 @@ static void *ThreadCode(void *p) } else { - printf("Bad request\n"); + if (!close_connection) + { + printf("Bad request\n"); + } } } -- cgit v1.2.3