working on adding different types of requests

This commit is contained in:
2025-10-06 13:41:12 -07:00
parent dba3bf3030
commit 5f058a01bf
3 changed files with 29 additions and 0 deletions

View File

@@ -127,8 +127,18 @@ void HttpRequestHeaderFromS(HttpRequestHeader* rh, char* buffer) {
int start, end = 0;
// Initialize the tokenization state
char** saveTokenState;
char* token;
// Tokenize the request line
token = strtok_r(buffer, " ", saveTokenState);
while ((token = strtok_r(NULL, " ", saveTokenState)) != NULL) {
// Tokenize
}
// GET /path/to/file/ HTTP:1.1
}

View File

@@ -35,8 +35,10 @@
#define HTTP_CONTENT_TYPE_IMAGE_PNG "image/png"
#define HTTP_CONTENT_TYPE_IMAGE_BMP "image/bmp"
#endif // HTTP_CONTENT_TYPES_H
#define HTTP_RECIVE_PACKET_SIZE 1024

View File

@@ -25,12 +25,29 @@ void handleClient(int sock) {
continue;
}
HttpRequestHeader rh;
char packetBuilder[HTTP_RECIVE_PACKET_SIZE] = "";
int sizeOfPacket = recv(sock, packetBuilder, HTTP_RECIVE_PACKET_SIZE, 0);
char* packetBuffer = malloc(sizeOfPacket);
while ((sizeOfPacket = recv(sock, packetBuilder, HTTP_RECIVE_PACKET_SIZE, 0)) > 0) {
strncat(packetBuffer, packetBuilder, sizeOfPacket);
}
HttpRequestHeaderFromS(&rh, packetBuffer);
free(packetBuffer);
FILE* file = fopen("./web/index.html", "r");
if (file == NULL) {
perror("that file dose not exists");
return;
}
char* fileBuffer;
fseek(file, 0, SEEK_END);