1

Am done with pset6 but want to test if I implemented the server correctly but when I type in the URL (e.g: 192.#.#.#:port#/cat.jpg) into the browser as specified by David, I get the following error "505 HTTP Version Not Supported" which i think the server should not throw that error considering the fact that the http version is HTTP/1.1

I have tried all sorts and still cannot figure out where the issue is. Also tried running gdb but it appears it is not useable here.

see below my code where I think the issue may lie. Looking through the code the content of check_request[2] should be "HTTP/1.1" . Please help me out

Edit: removed most code

Relevant code:

//Check if the http version is "HTTP/1.1" if(strcasecmp(check_request[2], "HTTP/1.1") != 0) { printf("505 HTTP Version Not Supported\n"); continue;
}

6
  • Some body please help me out here, I am still battling with this and still no meaningful result. Please help
    – nezechi
    Commented Aug 11, 2015 at 6:17
  • @Chris what about this one? Bounty?
    – i_am_david
    Commented Aug 12, 2015 at 23:51
  • Sure if you want.
    – ChrisG
    Commented Aug 13, 2015 at 6:14
  • @ChrisG Done, good luck!
    – i_am_david
    Commented Aug 13, 2015 at 16:20
  • @nezechi Bounty has been set.
    – i_am_david
    Commented Aug 13, 2015 at 16:21

1 Answer 1

4
+50

First, recall what the spec says about the request-line:

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.

If you put some debugging prints into your code as such:

    //Check if the http version is "HTTP/1.1"
if(strcasecmp(check_request[2], "HTTP/1.1") != 0)
{
    for (int i = 0, n = strlen(check_request[2]); i < n; i++)
        printf("%i:'%i' ", i,check_request[2][i]);
    
    printf("505 HTTP Version Not Supported\n");
    continue;     
}

(used %i to get the decimal values so non-printable chars will be easier to see)

You will discover that check_request[2] is indeed not "HTTP/1.1"

jharvard@appliance (~/Dropbox/CS50x/2015/pset6): ./server -p 8080 public
Using /home/jharvard/Dropbox/CS50x/2015/pset6/public for server's root
Listening on port 8080
GET /cat.html HTTP/1.1
0:'72' 1:'84' 2:'84' 3:'80' 4:'47' 5:'49' 6:'46' 7:'49' 8:'13' 9:'10' 
505 HTTP Version Not Supported

In ASCII:

72 84 84 80 47 49 46 49 13 10
H  T  T  P  /  1  .  1  CR LF  

The carriage return and line feed must be stripped from the check_request[2] string in order for your strcasecmp to match.

7
  • +1, Probably will give bounty.. but will wait for maybe some more answers
    – i_am_david
    Commented Aug 14, 2015 at 1:47
  • Removing all the code isn't really fair for other answerers... A little code is needed to answer...
    – i_am_david
    Commented Aug 14, 2015 at 1:54
  • the code is simply hidden behind the 'edit' link, so as not to be in your face. there's nothing to stop you from clicking the link to see the code. But it means that you are intentionally doing so, and should be following the academic honesty policy (i.e., you have completed the problem set and aren't looking for the solution.)
    – curiouskiwi
    Commented Aug 14, 2015 at 2:26
  • @curiouskiwi, Thanks a lot....your response helped a lot. I wonder why I missed out such little detail. I have another problem which I believe am missing out something but can not seem to figure out what am missing out.
    – nezechi
    Commented Aug 17, 2015 at 7:32
  • @curiouskiwi, Thanks a lot....your response helped a lot. I wonder why I missed out such little detail. However guys, I have another problem which I believe am missing out something but can not seem to figure out what am missing out.
    – nezechi
    Commented Aug 17, 2015 at 7:58

You must log in to answer this question.

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