summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-08-16 02:46:51 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2010-08-16 02:46:51 +0200
commit9510dcdf4d03a69da1398bc408fb937485c3c76f (patch)
treef237eade1d92f3889f8c782be00e00d413ea7c51
parentaf2dad91e142d074d29863d4786d8afdd47965cd (diff)
Send proper HTTP headers in the get_raw response.
-rw-r--r--commands.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/commands.c b/commands.c
index f15c2c6..b2c989a 100644
--- a/commands.c
+++ b/commands.c
@@ -55,14 +55,38 @@ static void commands_get_raw(GSocketConnection *connection, const gchar *cmd) {
g_error(error->message);
}
+ GFileInfo *fi = g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_SIZE,
+ G_FILE_QUERY_INFO_NONE, NULL, &error);
+
+ if(fi == NULL) {
+ g_error(error->message);
+ }
+
+ goffset filesize = g_file_info_get_size(fi);
+ g_object_unref(fi);
+
+ GString *string = g_string_new(NULL);
+ g_string_append(string, "HTTP/1.1 200 OK\r\n");
+ g_string_append(string, "content-type: octet-stream\r\n");
+ g_string_append_printf(string, "content-length: %lu\r\n", filesize);
+ g_string_append(string, "\r\n");
+
+ if(g_output_stream_write_all(os, string->str, string->len, NULL, NULL,
+ &error) == FALSE) {
+ g_error(error->message);
+ }
+
+ g_string_free(string, TRUE);
+
gssize size = g_output_stream_splice(os, (GInputStream*)is,
G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE ||
G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
NULL, &error);
if(size == -1) {
- g_error(error->message);
+ g_warning(error->message);
+ } else {
+ g_debug("wrote %lu bytes of file data", size);
}
- g_debug("wrote %lu bytes of file data", size);
g_object_unref(is);
g_object_unref(file);