[rygel] server: Refactor request handling
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] server: Refactor request handling
- Date: Sun, 24 Apr 2016 18:39:17 +0000 (UTC)
commit c679a2b2df8f7f0f824313ea93d1a2d7229e6ebb
Author: Jens Georg <mail jensge org>
Date: Sat Feb 27 01:57:28 2016 +0100
server: Refactor request handling
There is no need to pass the whole HTTPGet, only pass the needed resources.
This greatly simplifies testing the MediaEngine
Signed-off-by: Jens Georg <mail jensge org>
.../rygel-dlna-available-seek-request.vala | 14 +++++---
.../rygel-dtcp-cleartext-request.vala | 23 ++++++++------
.../rygel-http-byte-seek-request.vala | 33 +++++++++++---------
src/librygel-server/rygel-http-get.vala | 24 +++++++++-----
.../rygel-http-time-seek-request.vala | 19 ++++++-----
5 files changed, 65 insertions(+), 48 deletions(-)
---
diff --git a/src/librygel-server/rygel-dlna-available-seek-request.vala
b/src/librygel-server/rygel-dlna-available-seek-request.vala
index f5fac73..2ed1997 100644
--- a/src/librygel-server/rygel-dlna-available-seek-request.vala
+++ b/src/librygel-server/rygel-dlna-available-seek-request.vala
@@ -35,11 +35,12 @@ public class Rygel.DLNAAvailableSeekRangeRequest : Rygel.HTTPSeekRequest {
*
* @param request The HTTP GET/HEAD request
*/
- internal DLNAAvailableSeekRangeRequest (HTTPGet request)
- throws HTTPSeekRequestError {
+ internal DLNAAvailableSeekRangeRequest (Soup.Message message,
+ Rygel.HTTPGetHandler handler)
+ throws HTTPSeekRequestError {
base ();
- var params = request.msg.request_headers.get_one
+ var params = message.request_headers.get_one
(GET_AVAILABLE_SEEK_RANGE_HEADER);
if (params == null) {
@@ -58,14 +59,15 @@ public class Rygel.DLNAAvailableSeekRangeRequest : Rygel.HTTPSeekRequest {
/**
* Return true if getAvailableSeekRange is supported.
*/
- public static bool supported (HTTPGet request) {
+ public static bool supported (Soup.Message message,
+ Rygel.HTTPGetHandler handler) {
return true;
}
/**
* Return true of the HTTPGet contains a getAvailableSeekRange request.
*/
- public static bool requested (HTTPGet request) {
- return (request.msg.request_headers.get_one (GET_AVAILABLE_SEEK_RANGE_HEADER) != null);
+ public static bool requested (Soup.Message message) {
+ return (message.request_headers.get_one (GET_AVAILABLE_SEEK_RANGE_HEADER) != null);
}
}
diff --git a/src/librygel-server/rygel-dtcp-cleartext-request.vala
b/src/librygel-server/rygel-dtcp-cleartext-request.vala
index 31666e8..a09fd8b 100644
--- a/src/librygel-server/rygel-dtcp-cleartext-request.vala
+++ b/src/librygel-server/rygel-dtcp-cleartext-request.vala
@@ -48,16 +48,18 @@ public class Rygel.DTCPCleartextRequest : Rygel.HTTPSeekRequest {
*/
public int64 total_size { get; private set; }
- public DTCPCleartextRequest (HTTPGet request) throws HTTPSeekRequestError,
- HTTPRequestError {
+ public DTCPCleartextRequest (Soup.Message message,
+ Rygel.HTTPGetHandler handler)
+ throws HTTPSeekRequestError,
+ HTTPRequestError {
base ();
int64 start, end, total_size;
// It's only possible to get the cleartext size from a MediaResource
// (and only if it is link protected)
- if (request.handler is HTTPMediaResourceHandler) {
- var resource = (request.handler as HTTPMediaResourceHandler)
+ if (handler is HTTPMediaResourceHandler) {
+ var resource = (handler as HTTPMediaResourceHandler)
.media_resource;
total_size = resource.cleartext_size;
if (total_size <= 0) {
@@ -71,7 +73,7 @@ public class Rygel.DTCPCleartextRequest : Rygel.HTTPSeekRequest {
total_size = UNSPECIFIED;
}
- unowned string range = request.msg.request_headers.get_one
+ unowned string range = message.request_headers.get_one
(DTCP_RANGE_HEADER);
if (range == null) {
@@ -144,13 +146,14 @@ public class Rygel.DTCPCleartextRequest : Rygel.HTTPSeekRequest {
this.total_size = total_size;
}
- public static bool supported (HTTPGet request) {
- return (request.handler is HTTPMediaResourceHandler)
- && (request.handler as HTTPMediaResourceHandler)
+ public static bool supported (Soup.Message message,
+ Rygel.HTTPGetHandler handler) {
+ return (handler is HTTPMediaResourceHandler)
+ && (handler as HTTPMediaResourceHandler)
.media_resource.is_cleartext_range_support_enabled ();
}
- public static bool requested (HTTPGet request) {
- return (request.msg.request_headers.get_one (DTCP_RANGE_HEADER) != null);
+ public static bool requested (Soup.Message message) {
+ return (message.request_headers.get_one (DTCP_RANGE_HEADER) != null);
}
}
diff --git a/src/librygel-server/rygel-http-byte-seek-request.vala
b/src/librygel-server/rygel-http-byte-seek-request.vala
index 8de1549..5f4e592 100644
--- a/src/librygel-server/rygel-http-byte-seek-request.vala
+++ b/src/librygel-server/rygel-http-byte-seek-request.vala
@@ -49,10 +49,12 @@ public class Rygel.HTTPByteSeekRequest : Rygel.HTTPSeekRequest {
public int64 total_size { get; set; }
- public HTTPByteSeekRequest (HTTPGet request) throws HTTPSeekRequestError,
- HTTPRequestError {
+ public HTTPByteSeekRequest (Soup.Message msg,
+ Rygel.HTTPGetHandler handler)
+ throws HTTPSeekRequestError,
+ HTTPRequestError {
base ();
- unowned string range = request.msg.request_headers.get_one ("Range");
+ unowned string range = msg.request_headers.get_one ("Range");
if (range == null) {
throw new HTTPSeekRequestError.INVALID_RANGE ("Range header not present");
}
@@ -61,7 +63,7 @@ public class Rygel.HTTPByteSeekRequest : Rygel.HTTPSeekRequest {
// The size (entity body size) may not be known up-front (especially
// for live sources)
- total_size = request.handler.get_resource_size ();
+ total_size = handler.get_resource_size ();
if (total_size < 0) {
total_size = UNSPECIFIED;
}
@@ -72,8 +74,8 @@ public class Rygel.HTTPByteSeekRequest : Rygel.HTTPSeekRequest {
// legality varies based on the context (e.g. DLNA 7.5.4.3.2.19.2,
// 7.5.4.3.2.20.1, 7.5.4.3.2.20.3)
if (!range.has_prefix ("bytes=")) {
- var msg = ("Invalid Range value (missing 'bytes=' field): '%s'");
- throw new HTTPSeekRequestError.INVALID_RANGE (msg, range);
+ var message = ("Invalid Range value (missing 'bytes=' field): '%s'");
+ throw new HTTPSeekRequestError.INVALID_RANGE (message, range);
}
var parsed_range = range.substring (6);
@@ -91,8 +93,8 @@ public class Rygel.HTTPByteSeekRequest : Rygel.HTTPSeekRequest {
}
if ((total_size != UNSPECIFIED) && (start_byte >= total_size)) {
- var msg = /*_*/("Range start value %lld is larger than content size %lld: '%s'");
- throw new HTTPSeekRequestError.OUT_OF_RANGE (msg,
+ var message = /*_*/("Range start value %lld is larger than content size %lld: '%s'");
+ throw new HTTPSeekRequestError.OUT_OF_RANGE (message,
start_byte,
total_size,
range);
@@ -113,8 +115,8 @@ public class Rygel.HTTPByteSeekRequest : Rygel.HTTPSeekRequest {
("Invalid Range end value: '%s'", range);
}
if (end_byte < start_byte) {
- var msg = /*_*/("Range end value %lld is smaller than range start value %lld: '%s'");
- throw new HTTPSeekRequestError.INVALID_RANGE (msg,
+ var message = /*_*/("Range end value %lld is smaller than range start value %lld: '%s'");
+ throw new HTTPSeekRequestError.INVALID_RANGE (message,
end_byte,
start_byte,
range);
@@ -129,19 +131,20 @@ public class Rygel.HTTPByteSeekRequest : Rygel.HTTPSeekRequest {
this.total_size = total_size;
}
- public static bool supported (HTTPGet request) {
+ public static bool supported (Soup.Message message,
+ Rygel.HTTPGetHandler handler) {
bool force_seek = false;
try {
- var hack = ClientHacks.create (request.msg);
+ var hack = ClientHacks.create (message);
force_seek = hack.force_seek ();
} catch (Error error) { }
- return force_seek || request.handler.supports_byte_seek ();
+ return force_seek || handler.supports_byte_seek ();
}
- public static bool requested (HTTPGet request) {
- return (request.msg.request_headers.get_one ("Range") != null);
+ public static bool requested (Soup.Message msg) {
+ return (msg.request_headers.get_one ("Range") != null);
}
// Leading "0"s cause try_parse() to assume the value is octal (see Vala
diff --git a/src/librygel-server/rygel-http-get.vala b/src/librygel-server/rygel-http-get.vala
index c737b22..d2084c7 100644
--- a/src/librygel-server/rygel-http-get.vala
+++ b/src/librygel-server/rygel-http-get.vala
@@ -117,12 +117,16 @@ public class Rygel.HTTPGet : HTTPRequest {
}
private async void handle_item_request () throws Error {
- var supports_time_seek = HTTPTimeSeekRequest.supported (this);
- var requested_time_seek = HTTPTimeSeekRequest.requested (this);
- var supports_byte_seek = HTTPByteSeekRequest.supported (this);
- var requested_byte_seek = HTTPByteSeekRequest.requested (this);
- var supports_cleartext_seek = DTCPCleartextRequest.supported (this);
- var requested_cleartext_seek = DTCPCleartextRequest.requested (this);
+ var supports_time_seek = HTTPTimeSeekRequest.supported (this.msg,
+ this.handler);
+ var requested_time_seek = HTTPTimeSeekRequest.requested (this.msg);
+ var supports_byte_seek = HTTPByteSeekRequest.supported (this.msg,
+ this.handler);
+ var requested_byte_seek = HTTPByteSeekRequest.requested (this.msg);
+ var supports_cleartext_seek = DTCPCleartextRequest.supported
+ (this.msg, this.handler);
+ var requested_cleartext_seek = DTCPCleartextRequest.requested
+ (this.msg);
var response_headers = this.msg.response_headers;
@@ -191,12 +195,13 @@ public class Rygel.HTTPGet : HTTPRequest {
try {
// Order is intentional here
if (supports_cleartext_seek && requested_cleartext_seek) {
- var cleartext_seek = new DTCPCleartextRequest (this);
+ var cleartext_seek = new DTCPCleartextRequest (this.msg,
+ this.handler);
debug ("Processing DTCP cleartext byte range request (bytes %lld to %lld)",
cleartext_seek.start_byte, cleartext_seek.end_byte);
this.seek = cleartext_seek;
} else if (supports_byte_seek && requested_byte_seek) {
- var byte_seek = new HTTPByteSeekRequest (this);
+ var byte_seek = new HTTPByteSeekRequest (this.msg, this.handler);
debug ("Processing byte range request (bytes %lld to %lld)",
byte_seek.start_byte, byte_seek.end_byte);
this.seek = byte_seek;
@@ -204,7 +209,8 @@ public class Rygel.HTTPGet : HTTPRequest {
// Assert: speed_request has been checked/processed
var speed = this.speed_request == null ? null
: this.speed_request.speed;
- var time_seek = new HTTPTimeSeekRequest (this, speed);
+ var time_seek = new HTTPTimeSeekRequest (this.msg,
+ this.handler, speed);
debug ("Processing time seek %s", time_seek.to_string ());
this.seek = time_seek;
} else {
diff --git a/src/librygel-server/rygel-http-time-seek-request.vala
b/src/librygel-server/rygel-http-time-seek-request.vala
index 22ed7e6..b4b090b 100644
--- a/src/librygel-server/rygel-http-time-seek-request.vala
+++ b/src/librygel-server/rygel-http-time-seek-request.vala
@@ -68,19 +68,21 @@ public class Rygel.HTTPTimeSeekRequest : Rygel.HTTPSeekRequest {
* @param request The HTTP GET/HEAD request
* @param speed An associated speed request
*/
- internal HTTPTimeSeekRequest (HTTPGet request, PlaySpeed ? speed)
+ internal HTTPTimeSeekRequest (Soup.Message message,
+ HTTPGetHandler handler,
+ PlaySpeed? speed)
throws HTTPSeekRequestError {
base ();
bool positive_rate = (speed == null) || speed.is_positive ();
bool trick_mode = (speed != null) && !speed.is_normal_rate ();
- this.total_duration = request.handler.get_resource_duration ();
+ this.total_duration = handler.get_resource_duration ();
if (this.total_duration <= 0) {
this.total_duration = UNSPECIFIED;
}
- var range = request.msg.request_headers.get_one (TIMESEEKRANGE_HEADER);
+ var range = message.request_headers.get_one (TIMESEEKRANGE_HEADER);
if (range == null) {
throw new HTTPSeekRequestError.INVALID_RANGE ("%s not present",
@@ -203,22 +205,23 @@ public class Rygel.HTTPTimeSeekRequest : Rygel.HTTPSeekRequest {
* This method utilizes elements associated with the request to determine if
* a TimeSeekRange request is supported for the given request/resource.
*/
- public static bool supported (HTTPGet request) {
+ public static bool supported (Soup.Message message,
+ HTTPGetHandler handler) {
bool force_seek = false;
try {
- var hack = ClientHacks.create (request.msg);
+ var hack = ClientHacks.create (message);
force_seek = hack.force_seek ();
} catch (Error error) { /* Exception means no hack needed */ }
- return force_seek || request.handler.supports_time_seek ();
+ return force_seek || handler.supports_time_seek ();
}
/**
* Return true of the HTTPGet contains a TimeSeekRange request.
*/
- public static bool requested (HTTPGet request) {
- var header = request.msg.request_headers.get_one (TIMESEEKRANGE_HEADER);
+ public static bool requested (Soup.Message message) {
+ var header = message.request_headers.get_one (TIMESEEKRANGE_HEADER);
return (header != null);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]