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;
}