This is related to my earlier question, but as it turns out that I mistyped the error code in server.c
and actually have a 501 Not Implemented
error (instead of a 505), I made a new question because the answer was good but I still have an issue.
Whenever I try to load cat.html
I get the 501 error now. According to the spec (http://cdn.cs50.net/2015/x/psets/6/pset6/pset6.html#validate_request_line), there are two things that should trigger this:
- If
absolute-path
doesn't contain.
(therefore a file extension) - If
request-target
doesn't begin with/
This is my condition for #1
if (strstr(line, ".") == NULL)
{
error(501);
continue;
}
And this is my condition for #2
else if (requestLine[REQUEST_TARGET][0] != '/')
{ // not implemented
error(501);
continue;
}
Someone on slack also suggested an alternate method, which confuses me because it doesn't seem to check either condition for 501 mentioned in the spec (not having "GET" is supposed to be 405 Method Not Allowed
)
char buffer[4];
strncpy(buffer, line, 4);
buffer[3] = 0;
char* method = "GET";
//if
if (strncmp(line, method, 3) != 0)
{
error(501);
continue;
}
I've already checked my lookup function and it should be getting the proper file extension, which is the other condition that should bring up a 501
error.
line
andrequestLine[REQUEST_TARGET]
This raises a red flag for me. I'm not saying that one or both are wrong, especially since I haven't seen your code, but are you using the right vars in both places? My next step would be to narrow down which of the three 501 errors is being thrown. I would insert 3 different printf() statements and see which one gets triggered. At least that will narrow down the problem. Once I did that, I'd print out the var being tested to try to see what is causing the problem. It's a start. – Cliff B Sep 6 '15 at 3:02line
andrequestLine[REQUEST_TARGET]
becauseformat string is not a string literal
. – Yami Medina Sep 6 '15 at 3:04printf("No period. line =%s.\n", line);
and similar printf statements for the other two. Note that the %s bumps against the = sign and has a period right after. That's so you see exactly what prints and have clear markers before and after, especially in the case of extra spaces, line feeds and other odd characters. – Cliff B Sep 6 '15 at 3:08