django-nonrel / djangotoolbox

Django tools for building nonrel backends
BSD 3-Clause "New" or "Revised" License
201 stars 124 forks source link

DynamicSiteIDMiddleware fails when application when the request.host is an IPv6 address #82

Open comandrei opened 6 years ago

comandrei commented 6 years ago

Environment:

Django==1.8.18
djangotoolbox==1.8.0
Python 2.7.6

When performing a request as http://[2406:da00:ff00::36f3:801a]:80, the process_request method will throw a ValueError while unpacking the host to determine domain/port combination.

def process_request(self, request):
        # Ignore port if it's 80 or 443
        if ':' in request.get_host():
            domain, port = request.get_host().split(':')
            if int(port) not in (80, 443):
                domain = request.get_host()
        else:
            domain = request.get_host().split(':')[0]