changes version from a double to a struct containing major and minor
This commit is contained in:
parent
cc9d367464
commit
16481ec708
19
src/http.c
19
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)
|
void parse_request_line(char** line, http_request* request)
|
||||||
{
|
{
|
||||||
char *tok, *ver;
|
char *tok, *ver, *num;
|
||||||
|
|
||||||
|
|
||||||
tok = strtok(*line, " "); // this is the method
|
tok = strtok(*line, " "); // this is the method
|
||||||
@ -80,8 +80,21 @@ void parse_request_line(char** line, http_request* request)
|
|||||||
perror("strtok");
|
perror("strtok");
|
||||||
exit(EXIT_FAILURE);
|
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)
|
void parse_http_request(char** buffer, http_request* request)
|
||||||
|
@ -7,10 +7,15 @@ typedef enum {
|
|||||||
UNKNOWN,
|
UNKNOWN,
|
||||||
} http_method_t;
|
} http_method_t;
|
||||||
|
|
||||||
|
struct http_version {
|
||||||
|
int major;
|
||||||
|
int minor;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
http_method_t method;
|
http_method_t method;
|
||||||
char* request_uri;
|
char* request_uri;
|
||||||
double version;
|
struct http_version version;
|
||||||
|
|
||||||
} http_request;
|
} http_request;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user