Merge pull request #12 from gutenbergtools/forwarded-headers

Forwarded headers
bugfix
eshellman 2019-05-10 18:18:51 -04:00 committed by GitHub
commit 2d3c1fb63e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 8 deletions

View File

@ -420,19 +420,21 @@ class OpenSearch (object):
host = cherrypy.request.headers.get ('X-Forwarded-Host', cherrypy.config['host'])
self.host = host.split (',')[-1].strip () # keep only the last hub
# turns out X-Forwarded-Protocol (X-Forwarded-Proto is the defacto standaard)
# is not a thing and has to be set in HAProxy
self.protocol = cherrypy.request.headers.get ('X-Forwarded-Protocol', 'https')
# sanity check
if self.host not in (cherrypy.config['all_hosts']):
self.host = cherrypy.config['host']
if self.protocol not in VALID_PROTOCOLS:
self.protocol = 'http'
self.protocol = 'https'
self.urlgen = routes.URLGenerator (
cherrypy.routes_mapper,
{
'HTTP_HOST': self.host,
'HTTPS': 1 if self.protocol == 'https' else 0,
'HTTPS': 1 ,
}
)
@ -898,7 +900,7 @@ class OpenSearch (object):
def format_canonical_bibrec_url (self, row):
""" Generate the rel=canonical bibrec url for a book. """
return self.url ('bibrec', host = self.file_host, protocol = 'http', id = row.pk, format = None)
return self.url ('bibrec', host = self.file_host, protocol = 'https', id = row.pk, format = None)
def format_thumb_url (self, row):
""" Generate the thumb url in results. """

View File

@ -80,24 +80,24 @@
<div class="h1"
title="Credits">Credits</div>
<a href="http://www.ibiblio.org" rel="nofollow"
<a href="https://www.ibiblio.org" rel="nofollow"
title="Project Gutenberg is hosted by ibiblio.">
<span class ="icon icon_hosted" />
</a>
<p>This web site uses only free software.</p>
<a href="http://httpd.apache.org/" rel="nofollow"
<a href="https://httpd.apache.org/" rel="nofollow"
title="Powered by Apache">
<span class="icon icon_apache" />
</a>
<a href="http://www.python.org" rel="nofollow"
<a href="https://www.python.org" rel="nofollow"
title="Powered by Python">
<span class="icon icon_python" />
</a>
<a href="http://www.postgresql.org" rel="nofollow"
<a href="https://www.postgresql.org" rel="nofollow"
title="Powered by PostgreSQL">
<span class="icon icon_postgres" />
</a>
@ -114,7 +114,7 @@
<div id="fb-root" />
<div id="print-head" class="noscreen">
<div class="center">http:${os.desktop_url}<br/><br/>${os.tagline}</div>
<div class="center">https:${os.desktop_url}<br/><br/>${os.tagline}</div>
</div>
<div id="screen-head" class="noprint">