This commit is contained in:
Win 2024-06-05 15:41:02 +07:00
parent bcc7058591
commit 800ba738dc
4 changed files with 19 additions and 5 deletions

View File

@ -3,10 +3,19 @@ CFLAGS = -g -Wall
TARGET = server TARGET = server
all: $(TARGET) .PATH: ${.CURDIR}/src
.OBJPATH: ${.CURDIR}/obj
$(TARGET): src/$(TARGET).c all: server
$(CC) $(CFLAGS) -o $(TARGET) src/$(TARGET).c
server: server.o file.o
$(CC) $(CFLAGS) -o server server.o file.o
server.o: server.c server.h
$(CC) $(CFLAGS) -c server.c
file.o: file.c file.h
$(CC) $(CFLAGS) -c
clean: clean:
$(RM) $(TARGET) $(RM) $(TARGET)

View File

@ -13,7 +13,7 @@ void get_file_path(char *uri, char *file_path) {
strncat(uri, "index.html", 11); strncat(uri, "index.html", 11);
} }
strncpy(file_path, "htdocs", 7); strncpy(file_path, file_dir, (int)sizeof(file_dir));
printf("%s\n", file_path); printf("%s\n", file_path);
strncat(file_path, uri, (int)sizeof(uri)); strncat(file_path, uri, (int)sizeof(uri));

View File

@ -2,3 +2,5 @@
void get_file_path(char *uri, char *file_path); void get_file_path(char *uri, char *file_path);
void get_mime_type(char *file, char *mime); void get_mime_type(char *file, char *mime);
static const char file_dir[] = "htdocs";

View File

@ -121,8 +121,11 @@ int main() {
fseek(file, 0, SEEK_SET); fseek(file, 0, SEEK_SET);
printf("Size of File: %ld\n", file_size); printf("Size of File: %ld\n", file_size);
char mime_type[15];
get_mime_type(uri, mime_type);
send_response(client_sock_fd, OK_HEAD, "text/html", file, file_size); send_response(client_sock_fd, OK_HEAD, mime_type, file, file_size);
fclose(file); fclose(file);
} }