In there is the following sentence:

  • if absolute-path does not contain a . (and thus a file extension), respond to the browser with 501 Not Implemented.

But when using the Staff's solution and trying to do, say:

GET /cat HTTP/1.1

then I receive 404 Not found

Am I not understanding the quoted sentence above correctly, or does the staff's solution have a bug?

How do you guys handle a missing dot in your server.c?

Do you respond with 501 or 404?

enter image description here

Hope no one understands that as an offence to the Staff's solution, I just want to know if I have to respond to that case with 404 or 501 :-)


The staff version has this test:

Ensure that path actually exists. Respond to the browser with 404 Not Found if not!

before the test for the . in the absolute-path so because /cat doesn't exist in the directory, the 404 is returned. if you had a file called cat in your directory, then the . test would then fail and you'd give a 501.

For example,

jharvard@appliance (~/Dropbox/CS50x/2015/pset6): ~cs50/pset6/server -p 8080 public
Using /home/jharvard/Dropbox/CS50x/2015/pset6/public for server's root
Listening on port 8080
GET cat HTTP/1.1
HTTP/1.1 501 Not Implemented
^CStopping server
jharvard@appliance (~/Dropbox/CS50x/2015/pset6): ls -alt
total 404
-rw-------  1 jharvard students      0 Aug 28 04:07 cat
drwxrwxr-x  3 jharvard students   4096 Aug 28 04:07 .
drwxr-xr-x 19 jharvard students   4096 Aug 22 05:26 ..
-rwx------  1 jharvard students  27878 Aug 19 12:38 server
-rw-------  1 jharvard students  21127 Aug 19 12:38 server.c

Notice that cat is a file in the directory, so the path check is okay. But it doesn't contain a . so the server returns 501.

  • So, is my assumption right, that the stuffs server.c will never hit a 501? Why then the dot check? I didn't found a way to provoke a 501 in the stuffs version. – Lex Aug 28 '15 at 5:37
  • You will get a 501 if you put a path that exists but that doesn't have a . as I explained. see my edit. – curiouskiwi Aug 28 '15 at 5:43
  • Uh-huh :) Gotcha. Ok, I'll adjust my code accordingly.... However, in your example you probably hit the "missing slash" check. But I totally agree with your clarification - Thanks a lot! – Lex Aug 28 '15 at 6:00

You must log in to answer this question.

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