Kevin Sooter - C-Web-Server#300
Kevin Sooter - C-Web-Server#300kevin-sooter wants to merge 8 commits intobloominstituteoftechnology:masterfrom
Conversation
codejoncode
left a comment
There was a problem hiding this comment.
int response_length = sprintf(response, "%s\n"
"Date: %s\n"
"Connection: close\n"
"Content-Length: %d\n"
"Content-Type: %s\n"
"\n"
"%s\n",
header, buffer, content_length, content_type, new_body);
Nice work Kevin. Sprintf provides a
Return Value
If successful, the total number of characters written is returned excluding the null-character appended at the end of the string, otherwise a negative number is returned in case of failure.
https://www.tutorialspoint.com/c_standard_library/c_function_sprintf.htm
codejoncode
left a comment
There was a problem hiding this comment.
Time functionality seems to work well.
A different approach :
time_t t1 = time(NULL);
struct tm *ltime = localtime(&t1);
int response_length = sprintf(response,
"%s\n"
"Date: %s" // asctime adds its own newline
"Connection: close\n"
"Content-Length: %d\n"
"Content-Type: %s\n"
"\n", // End of HTTP header
header,
asctime(ltime),
content_length,
content_type
);
asctime automatically adds a new line for you.
codejoncode
left a comment
There was a problem hiding this comment.
I like the alloc_entry function you have and the use of strdup.
This is pretty much what you are doing with it
struct cache_entry *alloc_entry(char *path, char *content_type, void *content, int content_length)
{
struct cache_entry *ce = malloc(sizeof *ce);
// Set the fields in the new cache entry
ce->path = malloc(strlen(path) + 1);
strcpy(ce->path, path);
ce->content_type = malloc(strlen(content_type) + 1);
strcpy(ce->content_type, content_type);
ce->content_length = content_length;
ce->content = malloc(content_length);
memcpy(ce->content, content, content_length);
return ce;
}
No description provided.