summaryrefslogtreecommitdiffhomepage
path: root/http.c
diff options
context:
space:
mode:
Diffstat (limited to 'http.c')
-rw-r--r--http.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/http.c b/http.c
index 7e886b4..a966121 100644
--- a/http.c
+++ b/http.c
@@ -34,21 +34,23 @@ int respond_only_status(const int fd, const enum status status)
/// \param fd File descriptor of the client socket
/// \param status HTTP response status code
/// \param body Content that will be sent
+/// \param size Size of the content in bytes
/// \return Negative value if an error was encountered; numbers of bytes written otherwise
-int respond_with_body(const int fd, const enum status status, const char * body)
+int respond_with_body(const int fd, const enum status status, const char * body, const int size)
{
static const char * pattern =
"HTTP/1.1 %s\r\n"
"Connection: close\r\n"
- "Content-Type: text/plain\r\n"
+ "Content-Type: application/json\r\n"
+ "Content-Size: %d\r\n"
"\r\n";
- if (0 > dprintf(fd, pattern, status_str[status]))
+ if (0 > dprintf(fd, pattern, status_str[status], size))
{
return -1; // TODO: Handle errors properly
}
- return write(fd, body, strlen(body));
+ return write(fd, body, size);
}
/// Collects request between calls to `poll`.