Provide a source link so we can comply with the AGPL
[mediagoblin.git] / mediagoblin / app.py
index 04eb2acc8fa2de3efb1f0c85adea3f02710aa1dd..0a57c09101e7db3944b59f10f594ec93aaf6fdb9 100644 (file)
@@ -1,5 +1,5 @@
 # GNU MediaGoblin -- federated, autonomous media hosting
-# Copyright (C) 2011 MediaGoblin contributors.  See AUTHORS.
+# Copyright (C) 2011, 2012 MediaGoblin contributors.  See AUTHORS.
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as published by
 
 import os
 import urllib
+import logging
 
 import routes
 from webob import Request, exc
 
-from mediagoblin import routing, meddleware
+from mediagoblin import routing, meddleware, __version__
 from mediagoblin.tools import common, translate, template
 from mediagoblin.tools.response import render_404
 from mediagoblin.tools import request as mg_request
@@ -31,6 +32,9 @@ from mediagoblin.init import (get_jinja_loader, get_staticdirector,
     setup_storage, setup_beaker_cache)
 
 
+_log = logging.getLogger(__name__)
+
+
 class MediaGoblinApp(object):
     """
     WSGI application of MediaGoblin
@@ -47,6 +51,7 @@ class MediaGoblinApp(object):
            (Note: setting 'celery_setup_elsewhere' also disables
            setting up celery.)
         """
+        _log.info("GNU MediaGoblin %s main server starting", __version__)
         ##############
         # Setup config
         ##############
@@ -122,6 +127,11 @@ class MediaGoblinApp(object):
         # The other option would be:
         # request.full_path = environ["SCRIPT_URL"]
 
+        # Fix up environ for urlgen
+        # See bug: https://bitbucket.org/bbangert/routes/issue/55/cache_hostinfo-breaks-on-https-off
+        if environ.get('HTTPS', '').lower() == 'off':
+            environ.pop('HTTPS')
+
         ## Attach utilities to the request object
         request.matchdict = route_match
         request.urlgen = routes.URLGenerator(self.routing, environ)
@@ -174,6 +184,14 @@ class MediaGoblinApp(object):
         for m in self.meddleware[::-1]:
             m.process_response(request, response)
 
+        # Reset the sql session, so that the next request
+        # gets a fresh session
+        try:
+            self.db.reset_after_request()
+        except TypeError:
+            # We're still on mongo
+            pass
+
         return response(environ, start_response)