Permalink
Browse files

Slapped in version number. Made logging messages better. Make fallbac…

…k logic smarter
  • Loading branch information...
1 parent e4d9955 commit da323f710f00acc1cf77d91e43ca842b62f7267e Mikko committed May 29, 2011
View
@@ -4,8 +4,7 @@ Introduction
==============
XSendFile is an enhancement over HTTP front end proxy protocol
-which allows offloading of file downloads to the front end web server
-(Apache / Nginx).
+which allows offloading of file uploads and downloads to the front end web server
``collective.xsendfile`` package adds XSendFile support for Plone.
@@ -18,6 +17,14 @@ which allows offloading of file downloads to the front end web server
XSendFile support is available as ``collective.xsendfile`` add-on for Plone.
+Supported front-end web servers
+
+* Apache
+
+* Nginx
+
+* Lighttpd
+
Installation
==============
@@ -28,7 +35,7 @@ Installation
* Enable XSendFile module on your front-end web server
and virtual host configuration
-* Turn on XSendFile in Plone control panel
+* In XSendFile Plone control panel, set HTTP header according to your server (Apache/Nginx)
Enabling collective.xsendfile in buildout
====================================================
@@ -45,6 +52,17 @@ Then include it in the buildout.cfg::
develop =
src/collective.xsendfile
+
+Plone 4.0 and older installation additions
+----------------------------------------------
+
+collective.xsendfile uses plone.app.registry.
+You also might need to set up proper ``extends = `` like
+for Dexterity version pindowns, so that you don't
+get version conflicts during running buildout.
+
+* http://plone.org/products/dexterity/documentation/how-to/install
+
XSendFile installation for Apache on Debian/Ubuntu
====================================================
@@ -158,13 +176,13 @@ More info
* http://kovyrin.net/2006/11/01/nginx-x-accel-redirect-php-rails/
-* http://celebnamer.celebworld.ws/stuff/mod_xsendfile/
-
Authors
==========
Georg Gogo. BERNHARD
gogo@bluedynamics.com
+Jens W. Klein
+
Mikko Ohtamaa
mikko@mfabrik.com
@@ -6,7 +6,7 @@
purge="False">
<configlet
- title="XSendfile Settings"
+ title="XSendFile Settings"
action_id="plone.app.event"
appId="plone.app.event"
category="Plone"
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
- <version>1</version>
<dependencies>
<dependency>profile-plone.app.registry:default</dependency>
</dependencies>
@@ -8,6 +8,7 @@
import re
from zope import component
+from zope.component import ComponentLookupError
from webdav.common import rfc1123_date
from zope.component import getUtility
@@ -17,14 +18,21 @@
from collective.xsendfile.interfaces import IxsendfileSettings
+logger = logging.getLogger('collective.xsendfile')
+
def index_html(self, instance=None, REQUEST=None, RESPONSE=None, disposition='inline'):
""" Inject X-Sendfile and X-Accel-Redirect headers into response. """
-
- logger = logging.getLogger('collective.xsendfile')
- registry = getUtility(IRegistry)
- settings = registry.forInterface(IxsendfileSettings)
-
+ try:
+ registry = getUtility(IRegistry)
+ settings = registry.forInterface(IxsendfileSettings)
+ except ComponentLookupError:
+ # This happens when collective.xsendfile egg is in place
+ # but add-on installer has not been run yet
+ settings = None
+ logger.warn("Could not load collective.xsendfile settings")
+
+
if REQUEST is None:
REQUEST = instance.REQUEST
if RESPONSE is None:
@@ -43,30 +51,36 @@ def index_html(self, instance=None, REQUEST=None, RESPONSE=None, disposition='in
blob_file = zodb_blob.open()
file_path = blob_file.name
blob_file.close()
-
- responseheader = settings.xsendfile_responseheader
- pathregex_search = settings.xsendfile_pathregex_search
- pathregex_substitute = settings.xsendfile_pathregex_substitute
- enable_fallback = settings.xsendfile_enable_fallback
-
- if responseheader and pathregex_substitute:
- file_path = re.sub(pathregex_search,pathregex_substitute,file_path)
-
+
RESPONSE.setHeader('Last-Modified', rfc1123_date(instance._p_mtime))
RESPONSE.setHeader("Content-Length", blob.get_size())
RESPONSE.setHeader('Content-Type', self.getContentType(instance))
- fallback = False
- if not responseheader:
- fallback = True
- if enable_fallback:
- if (not REQUEST.get('HTTP_X_FORWARDED_FOR')):
+ if settings is not None:
+ responseheader = settings.xsendfile_responseheader
+ pathregex_search = settings.xsendfile_pathregex_search
+ pathregex_substitute = settings.xsendfile_pathregex_substitute
+ enable_fallback = settings.xsendfile_enable_fallback
+
+ if responseheader and pathregex_substitute:
+ file_path = re.sub(pathregex_search,pathregex_substitute,file_path)
+
+ fallback = False
+ if not responseheader:
fallback = True
+ logger.warn("No front end web server type selected")
+ if enable_fallback:
+ if (not REQUEST.get('HTTP_X_FORWARDED_FOR')):
+ fallback = True
+
+ else:
+ # Not yet installed through add-on installer
+ fallback = True
if fallback:
- logger.log(logging.WARNING, "Falling back to sending object %s.%s via Zope - no HTTP_X_FORWARDED_FOR header found."%(repr(instance),repr(self), ))
+ logger.warn("Falling back to sending object %s.%s via Zope"%(repr(instance),repr(self), ))
return zodb_blob.open().read()
else:
- logger.log(logging.INFO, "Sending object %s.%s with xsendfile header %s, path: %s"%(repr(instance), repr(self), repr(responseheader), repr(file_path)))
+ logger.debug("Sending object %s.%s with xsendfile header %s, path: %s"%(repr(instance), repr(self), repr(responseheader), repr(file_path)))
RESPONSE.setHeader(responseheader, file_path)
return "collective.xsendfile - proxy missing?"
View
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
import os
-version = '1.0'
+version = '1.1b1'
setup(name='collective.xsendfile',
version=version,

0 comments on commit da323f7

Please sign in to comment.