[rygel] core,tests: Fix byte range header check
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] core,tests: Fix byte range header check
- Date: Thu, 5 Apr 2012 21:21:50 +0000 (UTC)
commit 5dd1c3b7fa3bbaaccfe1a23ce50febada4a615f9
Author: Jens Georg <mail jensge org>
Date: Thu Apr 5 21:54:00 2012 +0200
core,tests: Fix byte range header check
Seems I was too optimistic with what the libsoup function can do.
src/rygel/rygel-http-byte-seek.vala | 22 +++++++++++++++++-----
tests/rygel-http-byte-seek-test.vala | 20 ++++++++++++++++++++
2 files changed, 37 insertions(+), 5 deletions(-)
---
diff --git a/src/rygel/rygel-http-byte-seek.vala b/src/rygel/rygel-http-byte-seek.vala
index fa5f536..556ef75 100644
--- a/src/rygel/rygel-http-byte-seek.vala
+++ b/src/rygel/rygel-http-byte-seek.vala
@@ -25,6 +25,7 @@ internal class Rygel.HTTPByteSeek : Rygel.HTTPSeek {
public HTTPByteSeek (HTTPGet request) throws HTTPSeekError {
Soup.Range[] ranges;
int64 start = 0, total_length;
+ unowned string range = request.msg.request_headers.get_one ("Range");
if (request.thumbnail != null) {
total_length = request.thumbnail.size;
@@ -35,11 +36,22 @@ internal class Rygel.HTTPByteSeek : Rygel.HTTPSeek {
}
var stop = total_length - 1;
- if (request.msg.request_headers.get_ranges (total_length,
- out ranges)) {
- // TODO: Somehow deal with multipart/byterange properly
- start = ranges[0].start;
- stop = ranges[0].end;
+ if (range != null) {
+ if (request.msg.request_headers.get_ranges (total_length,
+ out ranges)) {
+ // TODO: Somehow deal with multipart/byterange properly
+ start = ranges[0].start;
+ stop = ranges[0].end;
+ } else {
+ // Range header was present but invalid
+ throw new HTTPSeekError.INVALID_RANGE (_("Invalid Range '%s'"),
+ range);
+ }
+
+ if (start > stop) {
+ throw new HTTPSeekError.INVALID_RANGE (_("Invalid Range '%s'"),
+ range);
+ }
}
base (request.msg, start, stop, 1, total_length);
diff --git a/tests/rygel-http-byte-seek-test.vala b/tests/rygel-http-byte-seek-test.vala
index d0a82cc..c370613 100644
--- a/tests/rygel-http-byte-seek-test.vala
+++ b/tests/rygel-http-byte-seek-test.vala
@@ -82,6 +82,16 @@ private class Rygel.HTTPGet : GLib.Object {
this.add_headers (start, stop);
}
+ public HTTPGet.inverted_range () {
+ this (null, null);
+ this.msg.request_headers.append ("Range", "bytes=34-0");
+ }
+
+ public HTTPGet.invalid_range () {
+ this (null, null);
+ this.msg.request_headers.append ("Range", "bytes=a-b");
+ }
+
private void add_headers (int64 start, int64 stop) {
this.msg.request_headers.set_range (start, stop);
}
@@ -118,6 +128,16 @@ private class Rygel.HTTPByteSeekTest : GLib.Object {
this.test_start_stop_seek (thumbnail, subtitle);
}
}
+
+ try {
+ new HTTPByteSeek (new HTTPGet.inverted_range ());
+ assert_not_reached ();
+ } catch (HTTPSeekError error) {}
+
+ try {
+ new HTTPByteSeek (new HTTPGet.invalid_range ());
+ assert_not_reached ();
+ } catch (HTTPSeekError error) {}
}
private HTTPByteSeekTest () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]