0

When trying to access cat.html in pset6 on my local host, I get a 505: HTTP Version Not Supported error in both the browser and the terminal where my server is running.

According to my server.c code, these are the conditions that would make this error appear:

printf("http=%s#\n",http); 

    if (http == NULL)   
    {
        printf("it's null\n");
    }
    if (strcmp("HTTP/1.1", http))
    {
        printf("strcmp\n"); 
    }
    // if (http == NULL || strcmp("HTTP/1.1", http) != 0)
    if (http == NULL || !strcmp("HTTP/1.1", http)) 
    { // http version not supported
        error(505);
        continue;
    }

changing the if statement to if (http == NULL || strcasecmp("HTTP/1.1", http) != 0) still gives me the same error.

or this

        char* space = strchr(line, ' ');
        int length = space - line;
        char buffer[length + 1];

        if (buffer[length + 1] != '/')
        {
            error(505);
            continue;
        }
        strncpy(buffer, line, length);
        buffer[length] = 0;

When I print out http, it shows http=HTTP/1.1#, so I attempted a simple hacky solution that added the pound sign to the strcasecmp comparison, but it doesn't get rid of the error.

About a month ago, I spent a lot of time on the slack channel as well as with the TAs on my offline course, and they didn't quite understand what was going wrong either.

EDIT:

http is defined like this:

char* http = requestLine[HTTP_VERSION];
http[8] = '\0';

(I can post more code snippets if needed)

7
  • printf("http=%s#\n",http); explains why you get that # at the end. You put it there. – curiouskiwi Sep 3 '15 at 20:11
  • @curiouskiwi so would removing that line solve it? It was an attempt at debugging to figure out what was happening so that I could fix the problem. – Yami Medina Sep 3 '15 at 20:12
  • I don't know if it would fix it or not, but you were wondering why it showed there, so that was what my comment addressed. – curiouskiwi Sep 3 '15 at 20:17
  • @curiouskiwi I commented out that printf statement, but it didn't help. still getting the same 505 error. – Yami Medina Sep 3 '15 at 20:21
  • Perhaps you need to show us how you calculate http – curiouskiwi Sep 3 '15 at 22:52
0

This is causing your 505:

char buffer[length + 1];

    if (buffer[length + 1] != '/')
    {
        error(505);
        continue;
    }

You have declared the buffer but not initialised it. As such, it is full of "garbage" (whatever values were already existing in that bit of memory). When you then check for a particular value, it will fail (unless by some luck, that particular char had a / in it.)

Be sure to populate your buffer with the correct values before testing it.

4
  • The problem is that this part comes several hundred lines before the extensions are found, so I can't initialize it that way (unless moving it wouldn't mess up a ton of other things). Initializing buffer to 0 help tells me that a variable sized object cannot be initialized. – Yami Medina Sep 4 '15 at 13:11
  • Aren't you populating it in the next line by using strncpy? strncpy(buffer, line, length); buffer[length] = 0; – curiouskiwi Sep 4 '15 at 22:18
  • I have those two lines AFTER the of statement checks, which looking at it now is probably causing the problem. – Yami Medina Sep 5 '15 at 2:09
  • unfortunately, moving those two lines above the if statement didn't get rid of the 505 error either. – Yami Medina Sep 5 '15 at 2:38

You must log in to answer this question.

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