this.subtitle_index = -1;
}
- protected override async void handle () {
+ protected override async void handle () throws Error {
this.server.pause_message (this.msg);
yield base.handle ();
/* We only entertain 'HEAD' and 'GET' requests */
if ((this.msg.method != "HEAD" && this.msg.method != "GET") ||
(header != null && header != "1")) {
- this.handle_error (new HTTPRequestError.BAD_REQUEST (
- _("Invalid Request")));
- return;
+ throw new HTTPRequestError.BAD_REQUEST (_("Invalid Request"));
}
- try {
- if (uri.transcode_target != null) {
- var transcoder = this.http_server.get_transcoder (
+ if (uri.transcode_target != null) {
+ var transcoder = this.http_server.get_transcoder (
uri.transcode_target);
- this.handler = new HTTPTranscodeHandler (transcoder,
- this.cancellable);
- }
- } catch (Error err) {
- warning (_("Failed to parse query: %s"), err.message);
+ this.handler = new HTTPTranscodeHandler (transcoder,
+ this.cancellable);
}
if (this.handler == null) {
yield this.handle_item_request ();
}
- protected override async void find_item () {
+ protected override async void find_item () throws Error {
yield base.find_item ();
if (this.uri.thumbnail_index >= 0) {
}
}
- private async void handle_item_request () {
- try {
- if (HTTPTimeSeek.needed (this)) {
- this.seek = new HTTPTimeSeek (this);
- } else if (HTTPByteSeek.needed (this)) {
- this.seek = new HTTPByteSeek (this);
- }
-
- // Add headers
- this.handler.add_response_headers (this);
- debug (_("Following HTTP headers appended to response:"));
- this.msg.response_headers.foreach ((name, value) => {
- debug ("%s : %s", name, value);
- });
-
- if (this.msg.method == "HEAD") {
- // Only headers requested, no need to send contents
- this.server.unpause_message (this.msg);
- this.end (Soup.KnownStatusCode.OK);
- return;
- }
-
- var response = this.handler.render_body (this);
-
- yield response.run ();
-
- this.end (Soup.KnownStatusCode.NONE);
- } catch (Error error) {
- this.handle_error (error);
+ private async void handle_item_request () throws Error {
+ if (HTTPTimeSeek.needed (this)) {
+ this.seek = new HTTPTimeSeek (this);
+ } else if (HTTPByteSeek.needed (this)) {
+ this.seek = new HTTPByteSeek (this);
}
- }
- protected override void handle_error (Error error) {
- this.server.unpause_message (this.msg);
+ // Add headers
+ this.handler.add_response_headers (this);
+ debug (_("Following HTTP headers appended to response:"));
+ this.msg.response_headers.foreach ((name, value) => {
+ debug ("%s : %s", name, value);
+ });
+
+ if (this.msg.method == "HEAD") {
+ // Only headers requested, no need to send contents
+ this.server.unpause_message (this.msg);
+ this.end (Soup.KnownStatusCode.OK);
+ return;
+ }
+
+ var response = this.handler.render_body (this);
+
+ yield response.run ();
- base.handle_error (error);
+ this.end (Soup.KnownStatusCode.NONE);
}
}
base (http_server, server, msg);
}
- protected override async void handle () {
+ protected override async void handle () throws Error {
this.msg.got_chunk.connect (this.on_got_chunk);
this.msg.got_body.connect (this.on_got_body);
this.server.pause_message (this.msg);
yield base.handle ();
- try {
- this.file = yield this.item.get_writable (this.cancellable);
- if (this.file == null) {
- throw new HTTPRequestError.BAD_REQUEST (
+ this.file = yield this.item.get_writable (this.cancellable);
+ if (this.file == null) {
+ throw new HTTPRequestError.BAD_REQUEST (
_("No writable URI for %s available"),
this.item.id);
- }
+ }
- this.stream = yield this.file.replace_async (
+ this.stream = yield this.file.replace_async (
null,
false,
FileCreateFlags.REPLACE_DESTINATION,
Priority.LOW,
this.cancellable);
- } catch (Error error) {
- this.server.unpause_message (this.msg);
- this.handle_error (error);
-
- return;
- }
this.server.unpause_message (this.msg);
this.handle_continue = this.handle.callback;
}
public async void run () {
- yield this.handle ();
- }
-
- protected virtual async void handle () {
try {
- this.uri = new HTTPItemURI.from_string (this.msg.uri.path,
- this.http_server);
+ yield this.handle ();
} catch (Error error) {
this.handle_error (error);
return;
}
+ }
+
+ protected virtual async void handle () throws Error {
+ this.uri = new HTTPItemURI.from_string (this.msg.uri.path,
+ this.http_server);
yield this.find_item ();
}
- protected virtual async void find_item () {
+ protected virtual async void find_item () throws Error {
// Fetch the requested item
- MediaObject media_object;
- try {
- media_object = yield this.root_container.find_object (
+ var media_object = yield this.root_container.find_object (
this.uri.item_id,
null);
- } catch (Error err) {
- this.handle_error (err);
-
- return;
- }
if (media_object == null || !(media_object is MediaItem)) {
- this.handle_error (new HTTPRequestError.NOT_FOUND (
+ throw new HTTPRequestError.NOT_FOUND (
_("Requested item '%s' not found"),
- this.uri.item_id));
- return;
+ this.uri.item_id);
}
this.item = (MediaItem) media_object;
}
- protected virtual void handle_error (Error error) {
+ protected void handle_error (Error error) {
warning ("%s", error.message);
+ this.server.unpause_message (this.msg);
uint status;
if (error is HTTPRequestError) {