Use HTTP_X_FORWARDED_SCHEME to get correct scheme.
ClosedPublic

Authored by ralph2 on Nov 11 2014, 5:38 PM.

Details

Summary

This will make URLs returned by the resultsdb API have the correct scheme
prefix -- https instead of just 'http' like they do now (thus reducing
unnecessary redirects for clients that are paging through resultsdb results).

Here's a typical dump of the wsgi environment from our of our reverse
proxied app servers. As you can see, neither HTTP_X_SCHEME nor REQUEST_SCHEME
are quite correct.

{'CONTEXT_DOCUMENT_ROOT': '/var/www/html',
 'CONTEXT_PREFIX': '',
 'DOCUMENT_ROOT': '/var/www/html',
 'GATEWAY_INTERFACE': 'CGI/1.1',
 'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
 'HTTP_ACCEPT_ENCODING': 'gzip, deflate',
 'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.5',
 'HTTP_CACHE_CONTROL': 'max-age=0',
 'HTTP_HOST': 'taskotron.stg.fedoraproject.org',
 'HTTP_USER_AGENT': 'Mozilla/5.0 (X11; Linux x86_64; rv:33.0) Gecko/20100101 Firefox/33.0',
 'HTTP_X_FORWARDED_FOR': 'x.x.x.x',
 'HTTP_X_FORWARDED_HOST': 'taskotron.stg.fedoraproject.org',
 'HTTP_X_FORWARDED_SCHEME': 'https',
 'HTTP_X_FORWARDED_SERVER': 'taskotron.stg.fedoraproject.org',
 'PATH_INFO': '/api/v1.0/testcases',
 'PATH_TRANSLATED': '/var/www/html/api/v1.0/testcases',
 'QUERY_STRING': '',
 'REMOTE_ADDR': 'x.x.x.x',
 'REMOTE_PORT': '48146',
 'REQUEST_METHOD': 'GET',
 'REQUEST_SCHEME': 'http',
 'REQUEST_URI': '/resultsdb_api/api/v1.0/testcases',
 'SCRIPT_FILENAME': '/usr/share/resultsdb/resultsdb.wsgi',
 'SCRIPT_NAME': '/resultsdb_api',
 'SERVER_ADDR': 'x.x.x.x',
 'SERVER_ADMIN': 'root@localhost',
 'SERVER_NAME': 'resultsdb-stg01.qa.fedoraproject.org',
 'SERVER_PORT': '80',
 'SERVER_PROTOCOL': 'HTTP/1.0',
 'SERVER_SIGNATURE': '',
 'SERVER_SOFTWARE': 'Apache/2.4.10 (Fedora) mod_wsgi/3.5 Python/2.7.5',
 'mod_wsgi.application_group': '',
 'mod_wsgi.callable_object': 'application',
 'mod_wsgi.enable_sendfile': '0',
 'mod_wsgi.handler_script': '',
 'mod_wsgi.input_chunked': '0',
 'mod_wsgi.listener_host': '',
 'mod_wsgi.listener_port': '80',
 'mod_wsgi.process_group': 'resultsdb',
 'mod_wsgi.queue_start': '1415727086748691',
 'mod_wsgi.request_handler': 'wsgi-script',
 'mod_wsgi.script_reloading': '1',
 'mod_wsgi.version': (3, 5),
 'wsgi.multiprocess': False,
 'wsgi.multithread': True,
 'wsgi.run_once': False,
 'wsgi.url_scheme': 'http',
 'wsgi.version': (1, 0)}
Test Plan

Try it with a hot edit in the dev environment.

Diff Detail

Repository
rRSDB resultsdb
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
ralph2 retitled this revision from to Use HTTP_X_FORWARDED_SCHEME to get correct scheme..Nov 11 2014, 5:38 PM
ralph2 updated this object.
ralph2 edited the test plan for this revision. (Show Details)
ralph2 added reviewers: tflink, jskladan.
tflink added a subscriber: ralph.Nov 11 2014, 11:19 PM

@ralph Did you test this by hotfixing already or is that yet to be done?

I tested it with a hotfix in staging and then reverted it afterwards.

tflink accepted this revision.Nov 12 2014, 9:00 PM

If it's been tested, I have no objections

This revision is now accepted and ready to land.Nov 12 2014, 9:00 PM
This revision was automatically updated to reflect the committed changes.