0

I hope you are well! I am currently on pset6 and I am stuck on the parse function.

So far I have managed to get check50 to go all but green on a few checks: https://sandbox.cs50.net/checks/e1fbf75c46424277a5ab07228ed108c9

When I implement my check to ensure that the required method is GET, most of the other checks go red: https://sandbox.cs50.net/checks/09ea57ec48764112afe17eb1ebbfacde

Any ideas as to why this might be the case?

Kind regards, Adi (A CS50x student in London, UK)

Here's my code. I know that I have not implemented the "file not found" check yet, but I am taking things one at a time.

http://pastebin.com/0uuAxjsz

Update: Managed to get one of the method checks in check50 to go green but still stuck with the other one:

https://sandbox.cs50.net/checks/9dec5c506041486f928fb0d61cf4edce

Here's the pastebin with the update code: http://pastebin.com/f3FQvpN5

1 Answer 1

0

Lots of things going on here. It is definitely a good investment of time to learn how to use gdb (tips here) or debug50 to help troubleshoot server.

To start with, there is no return true; in this parse. Anything that does not fail one of the earlier tests will always give a 501 error and return false. That is part of the problem with the "non-existAnt file" test. There is no "file not found" test in parse, that is taken care of in another part of server. Read the server code from around line 185 (where parse is called) to get an idea how that works.

Once you fix that problem, there will still be problems with the "non-existant file" test. First review this part of the specification where it defines what a request-line and request-target look like.

Per 3.1.1 of https://www.rfc-editor.org/rfc/rfc7230, a request-line is defined as
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.
Per 5.3 of the same RFC, request-target, meanwhile, can take several forms, the only one of which your server needs to support is
absolute-path [ "?" query ]
whereby absolute-path (which will not contain ?) must start with / and might optionally be followed by a ? followed by a query, which may not contain ".

These two lines char* requestPath = strchr(line, forwardSlash); and strcpy(abs_path,requestPath); do not conform to the definition of abs_path. If the request-line is "GET /hello.html HTTP/1.1\r\n", then what will this strchr(line, forwardSlash) return? The routines to build abs_path and query need more work. (I'll say it again: gdb).

The failure of "GETabc" is here:

// Check if the request method is GET
char* method = strstr(line,"GET");

if (strncmp(line, method,sizeof(3)) != 0 )
{
    error (405);
    return false;
}

One problem with this sizeof(3). 3 is an integer, size of an integer is 4 or 8 depending on architecture. You probably meant 3.

Another problem: What will this strncmp(line, method,sizeof(3)) evaluate to if line includes "GETabc"? (and assuming the sizeof(3) is corrected). It will be true. What if you consider the first SP in request-line as part of method when writing the test?

This is just some low-hanging fruit. There could certainly be other problems either introduced by corrections or uncovered by corrections. Keep at it and you will have success.

3
  • Sorry for taking a long time to come back to you. I a look at your suggestions and incorporated them all. I set the final line to return true (as all the possible checks of the HTTP spec have been met. On the method part I did a strncmp on all chars of method and included a space. All that's left is the cat.exe issue and then I shall advance onto the second half of the pset! Commented Nov 1, 2016 at 0:09
  • Good work. A hint to testing for cat.exe: If you do not have a file named cat.exe in your public directory, you should always get a 404 error (file does not exist). check50 does have a cat.exe file (to make sure that lookup and parse work properly). You can copy cat.html to cat.exe in your public directory (cp cat.html cat.exe) and then you can test to make sure it gives a 501 as check50 expects. Commented Nov 1, 2016 at 11:22
  • Hello again! I finally got cat.exe check to work. I basically did an if check to see if cat.exe exists and gave the 501 error. I am now well into the second half of the problem set. Commented Nov 5, 2016 at 10:42

You must log in to answer this question.

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