diff --git a/server b/server index 6379fb5..f64d85a 100755 Binary files a/server and b/server differ diff --git a/src/server.c b/src/server.c index b3948c5..cd254c3 100644 --- a/src/server.c +++ b/src/server.c @@ -14,12 +14,11 @@ int send_response(int fd, char *header, char *content_type, void *body, int cont const int max_response_size = 65536; char response[max_response_size]; - time_t rawtime; - struct tm *info; - - info = localtime(&rawtime); - - int response_length = sprintf(response, + time_t current = time(NULL); + char date_time[30]; + strftime(date_time, sizeof(date_time), "%a, %d %b %Y %H:%M:%S %Z", localtime(¤t)); + + int header_length = sprintf(response, "%s\n" "Server: %s\n" "Date: %s\n" @@ -27,19 +26,24 @@ int send_response(int fd, char *header, char *content_type, void *body, int cont "Content-Length: %d\n" "Content-Type: %s\n" "\n", - header, SERVER_VERSION, asctime(info), content_length, content_type); + header, SERVER_VERSION, date_time, content_length, content_type); - memcpy(response + response_length, body, content_length); + printf("%s\n", (char *)body); + + //printf("%p\n", (char *)response); + //printf("%p\n", &header_length); + //printf("%p\n", (void *)(response + header_length)); + memcpy(response + header_length, body, content_length); printf("%s\n", response); - write(fd, response, response_length); + int write_res = write(fd, response, header_length + content_length); + + if (write_res < 0) { + perror("webserver (write)"); + return write_res; + } - //if (write < 0) { - // perror("webserver (write)"); - // return write; - //} - - return 0; + return write_res; } int main() { @@ -147,8 +151,9 @@ int main() { // } 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)); + int body_size = snprintf(body, 100, "%s\r\n", "hello what up bruh"); + printf("%d\n", body_size); + send_response(newsockfd, "HTTP/1.1 200 OK", "text/html", body, (body_size+1)); } // write to the socket