How to set wsgi.url_scheme to https in bottle?

by raven_corwin , in category: Third Party Scripts , 4 months ago

How to set wsgi.url_scheme to https in bottle?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by haylee.mertz , 4 months 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.