diff --git a/makefile b/makefile index 148e23a..eaebd20 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -CC=gcc +CC=clang all: webserver.c $(CC) webserver.c -o webserver diff --git a/webserver.c b/webserver.c index e1d00f4..7ecc892 100644 --- a/webserver.c +++ b/webserver.c @@ -1,7 +1,8 @@ -#include -#include #include #include +#include + +#include #include #include @@ -77,6 +78,16 @@ int main() { sscanf(buffer, "%s %s %s", method, uri, version); printf("[%s:%u] %s %s %s\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port), method, version, uri); + // check if request is GET request + if (strncmp("GET", method, 7) != 0) { + const char resp[] = "HTTP/1.0 400 Bad Request\r\n" + "Server: webserver-c\r\n" + "Content-type: text/html\r\n\r\n"; + write(newsockfd, resp, strlen(resp)); + } else { + // TO DO: IMPLEMENT FILE READING + } + // write to the socket int valwrite = write(newsockfd, resp, strlen(resp)); if (valwrite < 0) {