~ubuntu-branches/ubuntu/precise/rygel/precise

« back to all changes in this revision

Viewing changes to src/rygel/rygel-http-request-handler.vala

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Henriksson
  • Date: 2009-09-26 14:04:05 UTC
  • Revision ID: james.westby@ubuntu.com-20090926140405-d5x3j13k10psa1gu
Tags: upstream-0.4.1
ImportĀ upstreamĀ versionĀ 0.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2008, 2009 Nokia Corporation.
 
3
 *
 
4
 * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
 
5
 *                               <zeeshan.ali@nokia.com>
 
6
 *
 
7
 * This file is part of Rygel.
 
8
 *
 
9
 * Rygel is free software; you can redistribute it and/or modify
 
10
 * it under the terms of the GNU Lesser General Public License as published by
 
11
 * the Free Software Foundation; either version 2 of the License, or
 
12
 * (at your option) any later version.
 
13
 *
 
14
 * Rygel is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 * GNU Lesser General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU Lesser General Public License
 
20
 * along with this program; if not, write to the Free Software Foundation,
 
21
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
22
 */
 
23
 
 
24
using GUPnP;
 
25
 
 
26
/**
 
27
 * HTTP request handler interface.
 
28
 */
 
29
internal abstract class Rygel.HTTPRequestHandler: GLib.Object {
 
30
    public Cancellable cancellable { get; set; }
 
31
 
 
32
    // Add response headers.
 
33
    public virtual void add_response_headers (HTTPRequest request)
 
34
                                              throws HTTPRequestError {
 
35
        var mode = request.msg.request_headers.get ("transferMode.dlna.org");
 
36
        if (mode != null) {
 
37
            // FIXME: Is it OK to just copy the value of this header from
 
38
            // request to response? All we do to entertain this header is to
 
39
            // set the priority of IO operations.
 
40
            request.msg.response_headers.append ("transferMode.dlna.org", mode);
 
41
        }
 
42
 
 
43
        // Yes, I know this is not the ideal code to just get a specific
 
44
        // string for an HTTP header but if you think you can come-up with
 
45
        // something better, be my guest and provide a patch.
 
46
        var didl_writer = new GUPnP.DIDLLiteWriter (null);
 
47
        var didl_item = didl_writer.add_item ();
 
48
        var resource = this.add_resource (didl_item, request);
 
49
        var tokens = resource.protocol_info.to_string ().split (":", 4);
 
50
        assert (tokens.length == 4);
 
51
 
 
52
        request.msg.response_headers.append ("contentFeatures.dlna.org",
 
53
                                             tokens[3]);
 
54
    }
 
55
 
 
56
    // Create an HTTPResponse object that will render the body.
 
57
    public abstract HTTPResponse render_body (HTTPRequest request)
 
58
                                              throws HTTPRequestError;
 
59
 
 
60
    protected abstract DIDLLiteResource add_resource (DIDLLiteItem didl_item,
 
61
                                                      HTTPRequest  request)
 
62
                                                      throws HTTPRequestError;
 
63
}