Skip to content

wsgi.url_scheme doesn't follow X-Forwarded-Proto for gaiohttp #1055

@frensjan

Description

@frensjan

When using the gaiohttp worker with gunicorn behind a proxy I encountered wsgi.url_scheme not equallying X-Forwarded-Proto for https traffic. I.e. when rendering {{ request.META }} (in a Django template) the following seems incorrect to me:

{
 'wsgi.file_wrapper': <class 'aiohttp.wsgi.FileWrapper'>,
 'wsgi.run_once': False,
 'wsgi.version': (1, 0),
 'PATH_INFO': '/login/',
 'HTTP_COOKIE': 'django_language=nl; sessionid=doveg7trj7uyt0wet5xpo5thpcs3ha08; djdt=show; csrftoken=BFQ8iJExYCceNgNZW5tWIxQ0IY8aLfPL',
 'wsgi.multiprocess': False,
 'SERVER_PORT': '80',
 'wsgi.multithread': False,
 'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
 'SERVER_SOFTWARE': 'Python/3.4 aiohttp/0.16.5',
 'SERVER_PROTOCOL': 'HTTP/1.0',
 'wsgi.input': <_io.BytesIO object at 0x7f4cb80690a8>,
 'CSRF_COOKIE': 'BFQ8iJExYCceNgNZW5tWIxQ0IY8aLfPL',
 'REMOTE_PORT': '80',
 'HTTP_X_REAL_IP': '127.0.0.1',
 'REMOTE_ADDR': '127.0.0.1',
 'HTTP_X_FORWARDED_PROTO': 'https',
 'HTTP_USER_AGENT': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36',
 'HTTP_CACHE_CONTROL': 'max-age=0',
 'wsgi.errors': <_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'>,
 'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.8,nl;q=0.6,en-GB;q=0.4',
 'HTTP_HOST': 'localhost',
 'SCRIPT_NAME': '',
 'REQUEST_METHOD': 'GET',
 'async.writer': <aiohttp.parsers.StreamWriter object at 0x7f4cb80c7c18>,
 'async.reader': <aiohttp.parsers.StreamParser object at 0x7f4cb96134a8>,
 'QUERY_STRING': '',
 'HTTP_X_FORWARDED_FOR': '127.0.0.1',
 'SERVER_NAME': 'localhost',
 'HTTP_ACCEPT_ENCODING': 'gzip, deflate, sdch',
 'HTTP_CONNECTION': 'close',
 'RAW_URI': '/login/',
 'wsgi.async': True,
 'wsgi.url_scheme': 'http'
}

When starting gunicorn with the sync worker instead of gaiohttp the issue is resolved.

I'm using the following versions:

gunicorn==19.3.0
aiohttp==0.16.5

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions