0

Almost there, I'm only failing the following two tests now:

:( Requesting hello.php? returns 200, text/html, and correct output
   \ expected output, not an exit code of 0
:( Requesting hello.php?name=Alice returns 200, text/html, and correct output
   \ expected output, not an exit code of 0

I noticed that lookup is returning the type 'text/html' whenever I request the php page through hello.html:

Listening on port 8080
GET / HTTP/1.1
HTTP/1.1 200 OK
GET /hello.html HTTP/1.1
Type is: text/html
HTTP/1.1 200 OK
GET /hello.php?name=asd HTTP/1.1
Type is: text/html
HTTP/1.1 200 OK

As a result it's skipping over the if statement that interprets the php code:

if (strcasecmp("text/x-php", type) == 0)
{
   interpret(path, query);
}

But if I open hello.php, it works fine:

GET /hello.php HTTP/1.1
Type is: text/x-php

I'm pretty sure my lookup function is fine, but here it is anyway:

const char* lookup(const char* path)
{
    char* ending = strrchr(path, '.');

    if (strcasecmp(ending, ".css") == 0)
        return("text/css");
    else if (strcasecmp(ending, ".html") == 0)
        return("text/html");
    else if (strcasecmp(ending, ".gif") == 0)
        return("image/gif");
    else if (strcasecmp(ending, ".ico") == 0)
        return("image/x-icon");
    else if (strcasecmp(ending, ".jpg") == 0)
        return("image/jpeg");
    else if (strcasecmp(ending, ".js") == 0)
        return("text/javascript");   
    else if (strcasecmp(ending, ".php") == 0)
        return("text/x-php");
    else if (strcasecmp(ending, ".png") == 0)
        return("image/png");
    else
        return NULL;
}
1
  • Woops... I was correctly parsing the request-target into abs_path and query, however I wasn't using strcpy() to assign those values to the *abs_path and *query arguments passed into parse. So they were still using the previous values from when I loaded the hello.html page, which was why I was still getting the 'text/html' type, and skipping over interpret. (I think...)
    – jwld
    Sep 24 '16 at 17:10
1

Since those are the only two tests that fail check50, redirect your attention to how query is built in parse. Since hello.php "works fine", verify that query is properly null-terminated. A helpful format string for printf debugging is "%s<-" so your eye is not fooled by non-printing characters.

Where are you printing "Type is:"? I don't think it's skipping over the interpret call, otherwise you wouldn't get the right result when you request hello.php. Notice that the transfer function explicitly sets "Content-type" to the result of lookup and "respond"s with same. interpret does not; it "respond"s with info gleaned from the php-cgi header. Around line 518. Thus the "text/html" content type.

0

Thanks for the response DinoCoderSaurus. Literally just solved it - you were right the problem was in parse. I was correctly parsing the request-target into abs_path and query, however I wasn't using strcpy() to assign those values to the *abs_path and *query arguments passed into parse.

So they were still using the previous values from when I loaded the hello.html page, which was why I was still getting the 'text/html' type, and skipping over interpret. (I think...)

1
  • Glad you solved it! Now for some forum protocol. This "answer" should really be a comment. And for future reference, don't forget to accept, ie click the green check, answers that have value. Code on! Sep 24 '16 at 14:39

You must log in to answer this question.

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