changes version from a double to a struct containing major and minor

This commit is contained in:
SuperNovaa41 2025-01-29 09:52:34 -05:00
parent cc9d367464
commit 16481ec708
2 changed files with 22 additions and 4 deletions

View File

@ -46,7 +46,7 @@ const char* http_method_to_str(http_method_t input)
void parse_request_line(char** line, http_request* request)
{
char *tok, *ver;
char *tok, *ver, *num;
tok = strtok(*line, " "); // this is the method
@ -80,8 +80,21 @@ void parse_request_line(char** line, http_request* request)
perror("strtok");
exit(EXIT_FAILURE);
}
request->version = atof(ver);
num = strtok(ver, ".");
if (tok == NULL) {
perror("strtok");
exit(EXIT_FAILURE);
}
request->version.major = atoi(num);
num = strtok(NULL, ".");
if (tok == NULL) {
perror("strtok");
exit(EXIT_FAILURE);
}
request->version.minor = atoi(num);
}
void parse_http_request(char** buffer, http_request* request)

View File

@ -7,10 +7,15 @@ typedef enum {
UNKNOWN,
} http_method_t;
struct http_version {
int major;
int minor;
};
typedef struct {
http_method_t method;
char* request_uri;
double version;
struct http_version version;
} http_request;