1

Currently working on pset6 server.c. All of my pages load properly except for one thing: when I submit a name in the text box from hello.html, the query properly shows up in the URL, but the hello.html page content (i.e. the blank text box) loads instead of the hello.php page content. The correct output is a page that says "hello, david" that is generated by the hello.php file.

hello.html page content

Using curl, I see "Content-Type: text/html" after submitting curl -i http://localhost:8080/hello.php?name=david.

When I printf my abs_path and query variables at the end of my parse function, I get the following after requesting hello.html then submitting a name in the text box:

terminal output

Confusingly, when I request hello.php directly from the home page, the hello.php page properly loads:

hello.php working

I've been stumped for a while. Any tips on where the issue is stemming from?

Potentially useful update: When I enter "https://ide50-davidv.cs50.io/hello.php?name=david" in the URL while running GDB, I get a 301 error and get redirected to the home page ("/"):

GET /hello.php?name=david HTTP/1.1
abs_path: /hello.php
query: name=david
HTTP/1.1 301 Moved Permanently

1 Answer 1

1

So it looks like abs_path and query weren't properly being updated inside of my parse function, despite the printf results looking good. In main(), abs_path and query were empty.

Broken code:

// if request target has a ? 
else
{
    abs_path = strtok(request_target_copy, "?");
    query = strtok(NULL, "?");
    if (query == NULL)
    {
        query = "";
    }
}

Fixed code:

// if request target has a ? 
else
{
    const char* abs_path_copy = strtok(request_target_copy, "?");
    const char* query_copy = strtok(NULL, "?");
    if (query_copy == NULL)
    {
        query_copy = "";
    }
    strcpy(abs_path, abs_path_copy);
    strcpy(query, query_copy);
}

Server.c now works in its entirety. Not 100% sure if my solution is good practice...can anyone comment on that?

0

You must log in to answer this question.

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