I am having trouble with the pset6 parse function. I used check50 after implementing parse, and everything checks out except I get these two errors:
:( HTTP/1.0 returns error code 505 \ expected output, but not "HTTP/1.1 501 Not Implemented\r\nContent..."
:( Requesting non-existant file returns error code 404 \ expected output, but not "HTTP/1.1 501 Not Implemented\r\nContent..."
I am also not sure if I am setting abs_path and query correctly. It would be fantastic if y'all could help me resolve these problems. Thanks!
Here is my code:
//check if method is GET
if (line[0] != 'G' || line[1] != 'E' || line[2] != 'T' || line[3] != (char) 32)
{
error(405);
return false;
}
//check if request target contains "
if (strchr(line, '"') != NULL)
{
error(400);
return false;
}
//make sure request-line begins with '/'
for (int i = 0, j = strlen(line); i < j; i++)
{
if (line[i] == (char) 32)
{
if (line[i + 1] != '/')
{
error(501);
return false;
}
}
}
//check if http version is HTTP/1.1
for (int i = 4, j = strlen(line); i < j; i++)
{
if (line[i] == (char) 32)
{
if (line[i + 1] != 'H' || line[i + 2] != 'T' || line[i + 3] != 'T' || line[i + 4] != 'P' || line[i + 5] != '/' || line[i + 6] != '1' || line[i + 7] != '.' || line[i + 8] != '1')
{
error(505);
return false;
}
}
}
//variable to store abs_path
char* temp_ab_path = NULL;
//iterate over line to get abs-path
for (int i = 5, j = 32; line[i] != (char) j; i++)
{
//concatenate characters to abs_path
if (line[i] == (char) 32)
{
error(400);
return false;
}
strcat(temp_ab_path, &line[i]);
}
//variable to store optional query
char* q = NULL;
//iterate over line to see if there is a query
for (int i = 0, j = strlen(line); i < j; i++)
{
if (strcmp(&line[i], "?") == 0)
{
for (int k = i, l = 32; line[k] != (char) l; k++)
{
//concatenate the character to the string
strcat(q, &line[k]);
}
}
}
//set query and absolute path
abs_path = temp_ab_path;
query = q;
return true;