diff --git a/src/http.c b/src/http.c index 9239acf..4370595 100644 --- a/src/http.c +++ b/src/http.c @@ -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) diff --git a/src/include/http.h b/src/include/http.h index 832bbc8..01ce7d0 100644 --- a/src/include/http.h +++ b/src/include/http.h @@ -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;