title: How to set wsgi.url_scheme to https in bottle?
body: <p>I want to redirect all requests to <code>http</code> to <code>https</code>.  </p>
  
  <p>Is there a generic approach to setting <code>wsgi.url_scheme</code> to <code>https</code> in a Python 2.7 bottle application?</p>
  
  <p>The general structure of the application is:</p>
  
  <pre><code>setup.py  // contains 'install_requires'  
  wsgi  
   - myapplication.py  // the custom application containing bottle routes
  </code></pre>
  
  <p><code>wsgi.url_scheme</code> seems to be related to environment variables:</p>
  
  <p><a href="http://wsgi.readthedocs.org/en/latest/definitions.html#envvar-wsgi.url_scheme" rel="nofollow">http://wsgi.readthedocs.org/en/latest/definitions.html#envvar-wsgi.url_scheme</a></p>
  
  <p>But I'm not sure how to actually 'set' the environment variable to <code>https</code> and whether it can be done in the <code>setup.py</code> or <code>myapplication.py</code> files.  </p>
  
  <p>There is a snippet of code here:</p>
  
  <p><a href="https://github.com/defnull/bottle/issues/347" rel="nofollow">https://github.com/defnull/bottle/issues/347</a></p>
  
  <pre><code>def i_am_https_dammit(app):
      def https_app(environ, start_response):
          environ['wsgi.url_scheme'] = 'https'
          return app(environ, start_response)
      return https_app
  </code></pre>
  
  <p>But I don't know how I could implement the gist of this, as my call to the application is from <a href="https://github.com/FedericoCeratto/bottle-cork/blob/master/examples/simple_webapp_using_mongodb.py#L38" rel="nofollow">cork</a> and just uses:</p>
  
  <pre><code>application=default_app()  
  session_opts = {
      'session.cookie_expires': True,
      'session.encrypt_key': 'please use a random key and keep it secret!',
      'session.httponly': True,
      'session.timeout': 3600 * 24,  # 1 day
      'session.type': 'cookie',
      'session.validate_key': True,
  }
  application = SessionMiddleware(application, session_opts)
  </code></pre>