I'm getting two errors with check 50 and am struggling to understand how to go about this.
:( Requesting cat.exe returns error code 501
\ expected output, but not "HTTP/1.1 505 HTTP Version Not Supported..."
:( Requesting non-existant file returns error code 404
\ expected output, but not "HTTP/1.1 505 HTTP Version Not Supported..."
For the first one, I have this statement here that should check for that error, why isn't it working?
if(request_target[0]!= '/'){
error(501);
return false;
}
Also, Can anyone explain in pseudocode how to separate the absolute path and query? I was thinking of going to strtok()
way, but then that would make the question mark into a NULL and I wasn't sure if I needed to keep the question mark with anything?
Thanks.
Here's my whole code if that helps.
char* copyLine = malloc(sizeof(LimitRequestLine) + 1);
strcpy(copyLine,line);
char* method = malloc(sizeof(char*) + 100);
method = strtok(copyLine, " ");
char* request_target = malloc(sizeof(LimitRequestLine) + 1);
request_target= strtok(NULL, " ");
char* HTTP_version = malloc(sizeof(LimitRequestLine) + 1);
HTTP_version = strtok(NULL, " ");
if (strcasecmp(method, "GET") != 0) {
error(405);
return false;
}
if(request_target[0]!= '/'){
error(501);
return false;
}
//request_target cant have quote
if(strstr(request_target,"\"")!=NULL){
error(400);
return false;
}
if(strcasecmp(HTTP_version, "HTTP/1.1") != 0) {
error(505);
return false;
}
char* copy_abs_path = malloc(sizeof(LimitRequestLine) + 1);
//copy_abs_path = strtok(request_target, "?");
copy_abs_path = request_target;
char* copy_query = malloc(sizeof(LimitRequestLine) + 1);
// copy_query = strtok(NULL, " ");
for (int i = 0, n = strlen(copy_abs_path); i < n; i++){
if (copy_abs_path[i] == '/' && copy_abs_path[i+1] == '?') copy_query[0] = copy_abs_path[i+2];
if (copy_abs_path[i] == '/' && copy_abs_path[i+1] != '?') copy_query[0] = copy_abs_path[i+1];
// if (strlen(query)) < 1) query = "";
if (copy_query[0] == '\0') break;
}
abs_path = copy_abs_path;
query = copy_query;
//throw in errors
// strtok request target to check if query
//https://www.youtube.com/watch?v=d3kd5KbGB48
free(copyLine);
free(method);
free(request_target);
free(HTTP_version);
free(copy_abs_path);
free(copy_query);
return true;