Changeset 8691 for mauRepo/dj_security


Ignore:
Timestamp:
21/11/12 13:32:14 (7 years ago)
Author:
mnagni
Message:

corrects when netloc is empty and path is not

Location:
mauRepo/dj_security/trunk/dj_security
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • mauRepo/dj_security/trunk/dj_security/middleware.py

    r8690 r8691  
    7575    LOGGER.debug("calculating remote_ip for %s" % (str(remote_url))) 
    7676    port = 80 
    77     host = remote_url.netloc 
     77    host = None 
    7878    if remote_url.netloc: 
    79         if ':' in remote_url.netloc: 
    80             host, port = remote_url.netloc.split(':') 
    81         addrinfo = socket.getaddrinfo(host, int(port)) 
    82         LOGGER.debug("%s has remote_ip %s" % (url_path, addrinfo[0][-1][0]))                                  
    83         return addrinfo[0][-1][0] 
    84     return None 
     79        host = remote_url.netloc 
     80    elif remote_url.path: 
     81        host = remote_url.path 
     82         
     83    if not host: 
     84        return None 
     85     
     86    if ':' in host: 
     87        host, port = host.split(':') 
     88    addrinfo = socket.getaddrinfo(host, int(port)) 
     89    LOGGER.debug("%s has remote_ip %s" % (url_path, addrinfo[0][-1][0]))                                  
     90    return addrinfo[0][-1][0] 
  • mauRepo/dj_security/trunk/dj_security/test/test_middleware.py

    r8689 r8691  
    66import unittest 
    77from dj_security.middleware import _calculate_remote_ip 
     8import socket 
    89 
    910 
     
    1617        self._check_remote_ip('http://www.google.com/intl/it/about.html') 
    1718        self._check_remote_ip('http://www.google.com:80/intl/it/about.html') 
    18         #self._check_remote_ip('http://localhost') 
     19        self._check_remote_ip(socket.getfqdn()) 
    1920        #self._check_remote_ip('http://localhost:80') 
    2021 
Note: See TracChangeset for help on using the changeset viewer.