-
Notifications
You must be signed in to change notification settings - Fork 602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kevin Sooter - C-Web-Server #300
base: master
Are you sure you want to change the base?
Kevin Sooter - C-Web-Server #300
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.