Package flumotion :: Package component :: Package plugs :: Module requestmodifier
[hide private]

Source Code for Module flumotion.component.plugs.requestmodifier

 1  # -*- Mode: Python -*- 
 2  # -*- Encoding: UTF-8 -*- 
 3  # vi:si:et:sw=4:sts=4:ts=4 
 4   
 5  # Flumotion - a streaming media server 
 6  # Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L. 
 7  # Copyright (C) 2010,2011 Flumotion Services, S.A. 
 8  # All rights reserved. 
 9  # 
10  # This file may be distributed and/or modified under the terms of 
11  # the GNU Lesser General Public License version 2.1 as published by 
12  # the Free Software Foundation. 
13  # This file is distributed without any warranty; without even the implied 
14  # warranty of merchantability or fitness for a particular purpose. 
15  # See "LICENSE.LGPL" in the source distribution for more information. 
16  # 
17  # Headers in this file shall remain intact. 
18   
19  import os 
20  import urllib 
21   
22  from flumotion.common import python 
23  from flumotion.component.plugs import base 
24   
25  __version__ = "$Rev$" 
26   
27   
28 -class RequestModifierPlug(base.ComponentPlug):
29 """ 30 Base class for HTTP request modifier plug implementations. 31 """ 32
33 - def modify(self, request):
34 """ 35 Modify an HTTP request. 36 Can be used to modify the HTTP response. 37 38 @param request: the request to modify 39 @type request: twisted.web.server.Request 40 """ 41 pass
42 43
44 -class RequestModifierForceDownloadPlug(RequestModifierPlug):
45 46 logCategory = 'forcedownload' 47
48 - def start(self, component):
49 properties = self.args['properties'] 50 self._argument = properties['argument-name'] 51 self._triggers = python.set(properties.get('trigger-value', ['1'])) 52 self.log("Argument name: %s", self._argument) 53 self.log("Trigger values: %s", self._triggers)
54
55 - def modify(self, request):
56 if self._argument in request.args: 57 if self._triggers & python.set(request.args[self._argument]): 58 filename = os.path.basename(urllib.unquote_plus(request.path)) 59 filename = filename.encode('UTF-8') 60 filename = urllib.quote(filename) 61 header = "attachment; filename*=utf-8''%s" % filename 62 request.setHeader('Content-Disposition', header)
63