Skip to content
Myr

HEAD Support

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Kenneth Reitz · committed by Kenneth Reitz · parent 4f9d598 · Browse files · 1 file+10 added−15 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+10 added−15 removed

  • other:+10 added−15 removed

1 file+10 added−15 removed

modified:requests/core.py+10 added-15 removed
80 unmodified lines
81 :param anyway: If True, request will be sent, even if it has already been sent.82 """83 self._checks()84 85 if self.method.lower() == 'get':85 if self.method.lower() in ('get', 'head'):86 if (not self.sent) or anyway:87 try:88 # url encode GET params if it's a dict89 if isinstance(self.params, dict):
3 unmodified lines
93 params = self.params9495 req = urllib2.Request("%s?%s" % (self.url, params))9697 if self.method.lower() == 'head':98 req.get_method = lambda : 'HEAD'99100101 if self.headers:102 req.headers = self.headers103104 opener = self._get_opener()105 resp = opener(req)106107 self.response.status_code = resp.code108 self.response.headers = resp.info().dict109 if self.method.lower() == 'get':105 self.response.content = resp.read()110 self.response.content = resp.read()111112 success = True113109114 except RequestException:115 raise RequestException116 113 114 elif self.method.lower() == 'head':115 if (not self.sent) or anyway:116 try:117 pass118 119 success = True117121 except Exception:122 raise RequestException123 118 elif self.method.lower() == 'put':119 if (not self.sent) or anyway:120 try:121 pass
101 unmodified lines
223 224 return r.response225226233def head(url, data={}, headers={}, auth=None):227def head(url, params={}, headers={}, auth=None):228 """Sends a HEAD request. Returns :class:`Response` object.229 """230 r = Request()231 232 r.method = 'HEAD'233 r.url = url234 # return response object240 r.data = data235 r.params = params236 r.headers = headers237 r.auth = _detect_auth(url, auth)238 239 r.send()
82 unmodified lines