[ostree] trivial-httpd: Add --force-range-requests option to force range requests
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] trivial-httpd: Add --force-range-requests option to force range requests
- Date: Wed, 14 Aug 2013 21:44:54 +0000 (UTC)
commit 71f6f10cd282118b41516260dedce9b550e257b3
Author: Jeremy Whiting <jpwhiting kde org>
Date: Wed Aug 14 14:08:25 2013 -0600
trivial-httpd: Add --force-range-requests option to force range requests
This will be used to test resuming interrupted downloads for
ostree-pull.
With this option, if a whole file is asked for, only half of the file
is given. Then the client should retry with a range request, and
we'll give them the other half.
https://bugzilla.gnome.org/show_bug.cgi?id=705925
src/ostree/ot-builtin-trivial-httpd.c | 17 ++++++++++++++++-
1 files changed, 16 insertions(+), 1 deletions(-)
---
diff --git a/src/ostree/ot-builtin-trivial-httpd.c b/src/ostree/ot-builtin-trivial-httpd.c
index d6f85f5..f431eff 100644
--- a/src/ostree/ot-builtin-trivial-httpd.c
+++ b/src/ostree/ot-builtin-trivial-httpd.c
@@ -29,6 +29,7 @@
static char *opt_port_file = NULL;
static gboolean opt_daemonize;
static gboolean opt_autoexit;
+static gboolean opt_force_ranges;
typedef struct {
GFile *root;
@@ -39,6 +40,7 @@ static GOptionEntry options[] = {
{ "daemonize", 'd', 0, G_OPTION_ARG_NONE, &opt_daemonize, "Fork into background when ready", NULL },
{ "autoexit", 0, 0, G_OPTION_ARG_NONE, &opt_autoexit, "Automatically exit when directory is deleted", NULL
},
{ "port-file", 'p', 0, G_OPTION_ARG_FILENAME, &opt_port_file, "Write port number to PATH", "PATH" },
+ { "force-range-requests", 0, 0, G_OPTION_ARG_NONE, &opt_force_ranges, "Force range requests by only
serving half of files", NULL },
{ NULL }
};
@@ -199,6 +201,10 @@ do_get (OtTrivialHttpd *self,
{
GMappedFile *mapping;
SoupBuffer *buffer;
+ gsize buffer_length, file_size;
+ SoupRange *ranges;
+ int ranges_length;
+ gboolean have_ranges;
mapping = g_mapped_file_new (safepath, FALSE, NULL);
if (!mapping)
@@ -207,8 +213,17 @@ do_get (OtTrivialHttpd *self,
goto out;
}
+ file_size = g_mapped_file_get_length (mapping);
+ have_ranges = soup_message_headers_get_ranges(msg->request_headers, file_size, &ranges,
&ranges_length);
+ if (opt_force_ranges && !have_ranges)
+ buffer_length = file_size/2;
+ else
+ buffer_length = file_size;
+
+ if (have_ranges)
+ soup_message_headers_free_ranges (msg->request_headers, ranges);
buffer = soup_buffer_new_with_owner (g_mapped_file_get_contents (mapping),
- g_mapped_file_get_length (mapping),
+ buffer_length,
mapping, (GDestroyNotify)g_mapped_file_unref);
soup_message_body_append_buffer (msg->response_body, buffer);
soup_buffer_free (buffer);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]