Closed leffss closed 5 years ago
It's an issue of Heroku: https://help.heroku.com/J2R1S4T8/can-heroku-force-an-application-to-use-ssl-tls And I am not gonna fix it for the time being as it does not affect the use of ScrapydWeb.
@app.route('/hello')
def hello():
return 'Hello, World!'
Add the code block below to work around this issue.
# https://stackoverflow.com/questions/15116312/redirect-http-to-https-on-flaskheroku
# On Heroku, SSL (https) is terminated before it reaches your application,
# so you app never actually sees SSL traffic.
# request.url would always start with 'http://' even if
# you visit https://scrapydweb.herokuapp.com
# https://help.heroku.com/J2R1S4T8/can-heroku-force-an-application-to-use-ssl-tls
@app.after_request
def after_request(response):
from flask import request
from six.moves.urllib.parse import urljoin
if (request.headers.get('X-Forwarded-Proto') == 'https'
and 'Location' in response.headers):
# Location: /1/servers/
response.headers['Location'] = re.sub(r'^http://', 'https://',
urljoin(request.url, response.headers['Location']))
return response
thinks
为什么我的 heroku 应用访问 https 时,会 302 跳转到 http,是 heroku 的原因,还是 scrapydweb 的原因呢?