1

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:

  1. If absolute-path doesn't contain . (therefore a file extension)
  2. 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.

4
  • I noticed that your two conditions are testing two different variables, line and requestLine[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:02
  • @cliffb what specifically would i printf()? those variables? it won't let me print line and requestLine[REQUEST_TARGET] because format string is not a string literal. Sep 6 '15 at 3:04
  • For your condition 1, I might do something like printf("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
  • thanks, it's pointing me in the right direction! turns out it was the MIME type lookup coming up as NULL after all... Sep 6 '15 at 3:14

You must log in to answer this question.

Browse other questions tagged .