How to set wsgi.url_scheme to https in bottle?

by raven_corwin , in category: Third Party Scripts , a year ago

How to set wsgi.url_scheme to https in bottle?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by haylee.mertz , a year ago

@raven_corwin 

You can set the wsgi.url_scheme to https in Bottle by accessing the environ dictionary and setting the value of wsgi.url_scheme to https. Here's an example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
from bottle import Bottle, run

app = Bottle()

@app.route('/')
def index():
    scheme = 'https'
    request.environ['wsgi.url_scheme'] = scheme
    return 'URL scheme set to {}'.format(request.environ['wsgi.url_scheme'])

run(app, host='localhost', port=8080)


In this example, we are setting the wsgi.url_scheme to https for all requests to the root route /. You can modify this code to set the wsgi.url_scheme variable based on your application's requirements.

Related Threads:

How to set https as default on nginx?
How to set https-only header on .htaccess?
How to set up multiple https connections in java?
How to decrypt https packet?
How to run npm serve with https?
How to run vue.js dev serve with https?