small fixes

This commit is contained in:
Pin
2022-02-24 20:55:27 -05:00
parent 16801086ff
commit 7520553672
3 changed files with 8 additions and 4 deletions

View File

@@ -39,6 +39,7 @@ int parseHTTPRequest(unsigned char *buffer, struct HTTPRequest *r) {
int contentCheck = 0;
unsigned char *checkLine = calloc(1000, sizeof(unsigned char));
unsigned char *logLine = malloc(sizeof(unsigned char));
char * varCheck;
// Creating empty requestBody
r->requestBody = calloc(8, sizeof(char));
@@ -61,8 +62,11 @@ int parseHTTPRequest(unsigned char *buffer, struct HTTPRequest *r) {
strcpy(r->requestType, token);
// Grabbing HTTP Request Dir
token = strtok(NULL, " ");
r->requestDir = malloc(strlen(token));
strcpy(r->requestDir, token);
varCheck = strchr(token, '?');
if (varCheck != NULL) {
*varCheck = ' ';
}
sscanf(token, "%ms %ms", &r->requestDir, &r->requestVars);
// Grabbing HTTP Request Version
token = strtok(NULL, "");
token[strlen(token) - 1] = '\0'; // Fixing version end char
@@ -233,7 +237,7 @@ int handleRequest(unsigned char buffer[], int socket, SSL *ssl) {
if (checkerr != 0) { // Checking for HTTP parsing error
if (checkerr == -1) {
printDebug("Error reading request, returning empty 500");
return500Request(socket, ssl);
return return500Request(socket, ssl);
} else {
printDebug("Error parsing, returning 501");
return return501Request(socket, ssl);