0

I've been at Pset6 for ages now, and I'm stuck at this little tidbit here:

    } else if(versioning == true) {
        strcat(httpVersion, s);
        if(strncmp(httpVersion, "\"", 1) == 0) {
            error(400);
            abs_path = NULL;
            method = NULL;
            httpVersion = NULL;
            return false;
        }
    }
}
if(strncmp(httpVersion, "HTTP/1.1\r\n", strlen(httpVersion)) == 0) {
        return true;
} else {
    error(505);
    abs_path = NULL;
    method = NULL;
    httpVersion = NULL;
    return false;
}

The only two frowns I have in check50 are the following:

:( 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..."

I know where the problem roughly lies, but I have no idea how to fix it... It would be great if I could get some tips on how to go on.

1 Answer 1

2

It appears this if(strncmp(httpVersion, "HTTP/1.1\r\n", strlen(httpVersion)) == 0) { is always false, based on check50 output. Since program is comparing httpVersion to a string literal, one can draw the conclusion that httpVersion is "wrong". The only clue in the displayed code is strcat(httpVersion, s);. Absent other information, that leaves two possibilities. Either httpVersion doesn't start out as a "blank" string or s is "wrong".

For starters, you need to know what the computer thinks httpVersion is after it executes the strcat command. You could use printfs for that. (a format string like "%s<-" might help your eye detect any non-printing characters that might be lurking). Or you could use gdb. Running gdb with server is straightforward.

$ gdb ./server
(gdb) break parse
(gdb) run public

Then send a curl request in another terminal or a browser request. Something like curl -i http://localhost:8080/cat.exe might be a good place to start. One thing to remember: if it seems like "nothing is happening", gdb is probably waiting at a breakpoint.

You must log in to answer this question.

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