0

I'm working on pset6 Server. I have no idea what to do...want to test code but keep getting this message:

~/workspace/pset6/ $ curl -i http://localhost:8080/
curl: (7) Failed to connect to localhost port 8080: Connection refused

When I try to run server, I get this:

Using /home/ubuntu/workspace/pset6/public for server's root
Listening on port 8080
GET / HTTP/1.1
This is method extracted from line: GET
This is request target extracted from line: /
This is HTTP version extracted from line: HTTP/1.1

HTTP/1.1 505 HTTP Version Not Supported
GET /favicon.ico HTTP/1.1
This is method extracted from line: GET
This is request target extracted from line: /favicon.ico
This is HTTP version extracted from line: HTTP/1.1

HTTP/1.1 505 HTTP Version Not Supported

it seems to say http/1.1 is not supported, which stops all, but to me it looks like HTTP/1.1 is exactly what is supposed to be...? If I remove the "return false" from the HTTP version check, it gives a removed permanently message.

This is the piece of code from parse:

bool parse(const char* line, char* abs_path, char* query)
{
    // TODO
    // extracting absolute-path and query from line and store them at abs_path and query, respectively.
    // line is always constructed as: method SP request-target SP HTTP-version CRLF
    // Example: GET /cat.jpg HTTP/1.1\r\n 


    // Create variables for components and allocate memory
    char* checkline = malloc(LimitRequestLine +19);
    char* method = malloc(sizeof(char) * 5);
    char* request_target = malloc(LimitRequestLine);
    char* HTTP_version = malloc(sizeof(char)* 25);

    // copy line into checkline to be able to split it
    strcpy(checkline, line);

    // separate line into components unsing the delim
    method = strtok(checkline, " ");
    request_target =strtok(NULL, " ");
    HTTP_version = strtok(NULL, " ");
    printf("This is method extracted from line: %s\n", method);
    printf("This is request target extracted from line: %s\n", request_target);
    printf("This is HTTP version extracted from line: %s\n", HTTP_version);

    //if non goes well
    if ((method == NULL) || (request_target == NULL) || (HTTP_version == NULL)) {
        error(400);
        return false;
    }

    // if method is not GET, respond to the browser with 405 Method Not Allowed and return false
    if (strcmp(method, "GET") != 0)
    {
        error(405);
        return false;
    }

    // if request-target does not begin with /, respond to the browser with 501 Not Implemented and return false;
    if (request_target[0] != '/')
    {
        error(501);
        return false;
    }

    // if request-target contains a ", respond to the browser with 400 Bad Request and return false;
    if (strchr(request_target, '\"'))
    {
        error(400);
        return false;
    }

    // if HTTP-version is not HTTP/1.1, respond to the browser with 505 HTTP Version Not Supported and return false. 
    if (strcasecmp(HTTP_version, "HTTP/1.1") != 0)
    {
        error(505);
        return false;
    }
0

You got the first error most likely because you tried to use curl -i http://localhost:8080/ before starting your server with ./server public. You need to first start the server, then run curl.

About the HTTP version, you're probably forgetting that the request line ends with \r\n like this: "GET /favicon.ico HTTP/1.1\r\n", sou you'll need to deal with that \r\n at the end somehow.

If this solves your problem, please click the check mark to accept the answer.

2
  • Thanks Yuri! Feel a bit stupid to not have seen that myself... The HTTP version is solved now. 1 error down....99 more to go probably. But it still seems because I tried server too often and the port 8080 is somehow blocked. I deleted cookies and cache but still get the error code 301 Moved Permanently...I keep on trying to find out how what causes this.
    – Inge
    Nov 29 '16 at 11:40
  • You can probably solve the blocked port problem by executing the following command: killall server Please accept this answer if you solved the problem. Good luck! Nov 29 '16 at 11:51

You must log in to answer this question.

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