The two sad faces are the following: :( Requesting hello.php?name=Alice returns 200, text/html, and correct output and :( Requesting /test/ outputs /test/index.html
Here's the code:
bool load(FILE* file, BYTE** content, size_t* length)
{
int bytesRead = 0;
//create a buffer to hold an individual byte
char* buffer = malloc(sizeof(char));
//ensure that there was memory available
if(buffer == NULL)
return false;
//read through file byte by byte, increasing the allocated memory
//until the entire file is read
for(int newByte = fgetc(file); newByte != EOF; newByte = fgetc(file))
{
buffer[bytesRead] = (char)newByte;
bytesRead++;
buffer = realloc(buffer, (1+bytesRead) * sizeof(char));
}
*length = bytesRead;
*content = buffer;
return true;
}
Here's the part of parse that handles query:
//handle query
cursor = strstr(requestTarget, "?");
if(cursor != NULL)
{
if(*(cursor + 1) != '\0')
{
query = cursor + 1;
}
else query[0] = '\0';
strncpy(abs_path, requestTarget, cursor - requestTarget);
abs_path[cursor - requestTarget] = '\0';
}
else
{
query[0] = '\0';
strcpy(abs_path, requestTarget);
}
return true;