diff --git a/src/headers.c b/src/headers.c index 0bc58e3..e6de523 100644 --- a/src/headers.c +++ b/src/headers.c @@ -166,8 +166,8 @@ int headers_metadata(struct metaData* metaData, char* header) { char* _path = strtok(NULL, " "); if (_path == NULL) return HEADERS_PARSE_ERROR; - char* _httpVersion = strtok(NULL, " "); - if (_httpVersion == NULL) + char* _protocol = strtok(NULL, " "); + if (_protocol == NULL) return HEADERS_PARSE_ERROR; char* _null = strtok(NULL, " "); @@ -205,11 +205,11 @@ int headers_metadata(struct metaData* metaData, char* header) { else return HEADERS_PARSE_ERROR; - enum httpVersion httpVersion; - if (strcmp(_httpVersion, "HTTP/1.0") == 0) - httpVersion = HTTP10; - else if (strcmp(_httpVersion, "HTTP/1.1") == 0) - httpVersion = HTTP11; + enum protocol protocol; + if (strcmp(_protocol, "HTTP/1.0") == 0) + protocol = HTTP10; + else if (strcmp(_protocol, "HTTP/1.1") == 0) + protocol = HTTP11; else return HEADERS_PARSE_ERROR; @@ -236,7 +236,7 @@ int headers_metadata(struct metaData* metaData, char* header) { strcat(uri, queryString); metaData->method = method; - metaData->httpVersion = httpVersion; + metaData->protocol = protocol; metaData->path = path; metaData->queryString = queryString; metaData->uri = uri; @@ -268,3 +268,14 @@ const char* methodString(struct metaData metaData) { return NULL; } } + +const char* protocolString(struct metaData metaData) { + switch(metaData.protocol) { + case HTTP10: + return "HTTP/1.0"; + case HTTP11: + return "HTTP/1.1"; + default: + return NULL; + } +} diff --git a/src/headers.h b/src/headers.h index d235123..09a5b31 100644 --- a/src/headers.h +++ b/src/headers.h @@ -30,5 +30,6 @@ void headers_dump(struct headers* headers, FILE* stream); int headers_metadata(struct metaData* metaData, char* header); const char* methodString(struct metaData metaData); +const char* protocolString(struct metaData metaData); #endif diff --git a/src/misc.h b/src/misc.h index a63ed41..b70bec0 100644 --- a/src/misc.h +++ b/src/misc.h @@ -11,13 +11,13 @@ enum method { GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE, PATCH }; -enum httpVersion { +enum protocol { HTTP10, HTTP11 }; struct metaData { enum method method; - enum httpVersion httpVersion; + enum protocol protocol; char* path; char* queryString; char* uri;