diff --git a/Makefile b/Makefile index eaebd20..54fdb36 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CC=clang +CC=/usr/bin/clang all: webserver.c $(CC) webserver.c -o webserver diff --git a/goffy b/goffy deleted file mode 100755 index 7246061..0000000 Binary files a/goffy and /dev/null differ diff --git a/goffy.c b/goffy.c deleted file mode 100644 index f76ca5b..0000000 --- a/goffy.c +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include - -int main() { - - const char src[20] = "HA! poopoohead!"; - char dest[100]; - - int eh = sprintf(dest, "%s", "goofy"); - - memcpy(dest + 6, src, strlen(src) + 1); - - printf("Output: %s\n", dest); - - printf("src[0] %p\n", &src[0]); - printf("src[0] %p\n\n", src); - printf("src[1] %p\n", &src[1]); - printf("src[1] %p\n", src + 1); - printf("src[50] %p\n", src + 49); - - printf("%ld", sizeof(dest)); - - return 0; -} diff --git a/server b/server index 9c9a369..6379fb5 100755 Binary files a/server and b/server differ diff --git a/src/server.c b/src/server.c index 85713d6..b3948c5 100644 --- a/src/server.c +++ b/src/server.c @@ -10,10 +10,6 @@ #include "server.h" -/* - -TODO: CREATE SENDING RESPONSE FUNCTION - int send_response(int fd, char *header, char *content_type, void *body, int content_length) { const int max_response_size = 65536; char response[max_response_size]; @@ -25,17 +21,26 @@ int send_response(int fd, char *header, char *content_type, void *body, int cont int response_length = sprintf(response, "%s\n" - "Date: %s" + "Server: %s\n" + "Date: %s\n" "Connection: close\n" "Content-Length: %d\n" "Content-Type: %s\n" "\n", - header, asctime(info), content_length, content_type); + header, SERVER_VERSION, asctime(info), content_length, content_type); memcpy(response + response_length, body, content_length); -} + printf("%s\n", response); -*/ + write(fd, response, response_length); + + //if (write < 0) { + // perror("webserver (write)"); + // return write; + //} + + return 0; +} int main() { char buffer[BUFFER_SIZE]; @@ -126,20 +131,24 @@ int main() { continue; } } else { - char resp[100]; - int resp_size = snprintf(resp, 100, - "%s\r\n" - "Server: %s\r\n" - "Content-Type: %s\r\n" - "\r\n", - OK_HEAD, SERVER_VERSION, "text/html"); - - int valwrite = write(newsockfd, resp, resp_size); - printf("%s\n", OK_HEAD); - if (valwrite < 0) { - perror("webserver (write)"); - continue; - } + // char resp[100]; + // int resp_size = snprintf(resp, 100, + // "%s\r\n" + // "Server: %s\r\n" + // "Content-Type: %s\r\n" + // "\r\n", + // OK_HEAD, SERVER_VERSION, "text/html"); + // + // int valwrite = write(newsockfd, resp, resp_size); + // printf("%s\n", OK_HEAD); + // if (valwrite < 0) { + // perror("webserver (write)"); + // continue; + // } + + char body[100]; + int body_size = snprintf(body, 100, "%s\r\n", "hello"); + send_response(newsockfd, "HTTP/1.1 200 OK", "text/html", "deeznuts", sizeof(body_size)); } // write to the socket diff --git a/src/server.h b/src/server.h index 72ed635..7e9951b 100644 --- a/src/server.h +++ b/src/server.h @@ -1,7 +1,7 @@ #define PORT 8080 #define BUFFER_SIZE 1024 -static const char SERVER_VERSION[] = "winnie-http-server/0.0.1"; +static const char SERVER_VERSION[] = "winnie-http-server"; static const char BAD_REQUEST_HEAD[] = "HTTP/1.1 400 Bad Request"; static const char NOT_FOUND_HEAD[] = "HTTP/1.1 404 Not Found";