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 Fluendo, S.L. (www.fluendo.com). 
 7  # All rights reserved. 
 8   
 9  # This file may be distributed and/or modified under the terms of 
10  # the GNU General Public License version 2 as published by 
11  # the Free Software Foundation. 
12  # This file is distributed without any warranty; without even the implied 
13  # warranty of merchantability or fitness for a particular purpose. 
14  # See "LICENSE.GPL" in the source distribution for more information. 
15   
16  # Licensees having purchased or holding a valid Flumotion Advanced 
17  # Streaming Server license may use this file in accordance with the 
18  # Flumotion Advanced Streaming Server Commercial License Agreement. 
19  # See "LICENSE.Flumotion" in the source distribution for more information. 
20   
21  # Headers in this file shall remain intact. 
22   
23  import os 
24  import urllib 
25   
26  from flumotion.common import python 
27  from flumotion.component.plugs import base 
28   
29  __version__ = "$Rev$" 
30   
31   
32 -class RequestModifierPlug(base.ComponentPlug):
33 """ 34 Base class for HTTP request modifier plug implementations. 35 """ 36
37 - def modify(self, request):
38 """ 39 Modify an HTTP request. 40 Can be used to modify the HTTP response. 41 42 @param request: the request to modify 43 @type request: twisted.web.server.Request 44 """ 45 pass
46 47
48 -class RequestModifierForceDownloadPlug(RequestModifierPlug):
49 50 logCategory = 'forcedownload' 51
52 - def start(self, component):
53 properties = self.args['properties'] 54 self._argument = properties['argument-name'] 55 self._triggers = python.set(properties.get('trigger-value', ['1'])) 56 self.log("Argument name: %s", self._argument) 57 self.log("Trigger values: %s", self._triggers)
58
59 - def modify(self, request):
60 if self._argument in request.args: 61 if self._triggers & python.set(request.args[self._argument]): 62 filename = os.path.basename(urllib.unquote_plus(request.path)) 63 filename = filename.encode('UTF-8') 64 filename = urllib.quote(filename) 65 header = "attachment; filename*=utf-8''%s" % filename 66 request.setHeader('Content-Disposition', header)
67