Ticket #14955: urrlib2_head_request.diff

File urrlib2_head_request.diff, 1013 bytes (added by Claude Paroz, 14 years ago)

Use HEAD HTTP request instead of GET

  • django/core/validators.py

    diff --git a/django/core/validators.py b/django/core/validators.py
    index b1b82db..2fd1253 100644
    a b class URLValidator(RegexValidator):  
    7373
    7474        if self.verify_exists:
    7575            import urllib2
     76            class HeadRequest(urllib2.Request):
     77                def get_method(self):
     78                    return "HEAD"
    7679            headers = {
    7780                "Accept": "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5",
    7881                "Accept-Language": "en-us,en;q=0.5",
    class URLValidator(RegexValidator):  
    8184                "User-Agent": self.user_agent,
    8285            }
    8386            try:
    84                 req = urllib2.Request(url, None, headers)
     87                req = HeadRequest(url, None, headers)
    8588                u = urllib2.urlopen(req)
    8689            except ValueError:
    8790                raise ValidationError(_(u'Enter a valid URL.'), code='invalid')
Back to Top