I know that when lookup returns NULL when called, error 501 should appear and that's what I did in lookup's implementation. If the extension of the file is none of the ones mentioned in the pset's specs, return NULL. I don't know why I get the first error. For the second error, I have no idea how to make sure the file exists.

Lookup: https://gist.github.com/a37f7cd1cad7403346e8e7df90b57813

Parse: https://gist.github.com/86bfd699e66a7d55efe8c8fb0d3cfc6c


:) server.c exists

:) server compiles

:) HTTP/1.0 returns error code 505

:) Method of 'abcGET' returns error code 405

:) Method of 'GETabc' returns error code 405

:) request-target without starting '/' returns error code 501

:) request-target of abc/hello.php returns error code 501

:( 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..." :) Requesting request-target with " returns error code 400

:) Two spaces after GET returns error code

:) A space within the request target returns error code

:) Two spaces before HTTP/1.1 returns error code

ps: I haven't implemented the query part in parse yet.

1 Answer 1


There's only one place that server returns a 505, and that is from your parse function. Your server is never even getting to lookup. This guy if (strcmp(word, "HTTP/1.1") != 0) is always evaluating to false. Troubleshooting this would be a great job for gdb. Find some tips here.

Recall from the spec what a request line looks like:

method SP request-target SP HTTP-version CRLF

wherein SP represents a single space ( ) and CRLF represents \r\n. None of method, request-target, and HTTP-version, meanwhile, may contain SP.

There is no SP after the HTTP-version. This line word = strtok(NULL, " "); therefore will return everything up to the null byte. Which will include CRLF. Or maybe since message isn't declared as a string you might be getting unpredictable results. Either way.....

Regarding this char message[100]; allocation. You don't need to (read: shouldn't) randomly select how big to make message. Since you know you are going to strcpy(message, line); then you know it has to be the same length as line. (+1 for the null-terminator if you decide to make a realio trulio string, which might be a good idea since strtok expects strings).

Also this return 1; is wrong. parse is a bool function. 1 evaluates to true. It doesn't seem to bother check50/server1 (!), but it is wrong (the spec says to return false).

There is exactly one place in server that returns a 404 error code. You should read through the server code from around line 182 when parse is called, and understand how it determines and reports a 404 "Not Found" error.

  • Thanks for answering! I edited parse and managed to make one error go away. But still stuck at the other error: :( Requesting cat.exe returns error code 501 \ expected output, but not "HTTP/1.1 500 Internal Server Error\r\nC..." parse: gist.github.com/9acdaefcab4d9fb15a248d48c9e59edb Commented Aug 22, 2016 at 17:36
  • The old strcasecmp return trap (in lookup)! That function does NOT return a bool, it returns and int. If it returns and int, treat it like an int. Read man strcasecmp if you are in doubt about return value. Commented Aug 22, 2016 at 21:27
  • Solved! Thanks so much! Commented Aug 23, 2016 at 18:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .