56
56
def has(self, relpath):
57
57
self.curl = pycurl.Curl()
59
58
abspath = self.abspath(relpath)
60
59
if isinstance(abspath, unicode):
61
60
abspath = abspath.encode('ascii', 'strict')
62
# raise ValueError("paths passed to Transport must be plain strings: "
64
61
self.curl.setopt(pycurl.URL, abspath)
65
self._set_curl_cache_headers()
62
self.curl.setopt(pycurl.FOLLOWLOCATION, 1) # follow redirect responses
63
self._set_curl_options()
66
64
# don't want the body - ie just do a HEAD request
67
65
self.curl.setopt(pycurl.NOBODY, 1)
69
66
self._curl_perform()
72
68
code = self.curl.getinfo(pycurl.HTTP_CODE)
73
69
if code == 404: # not found
84
80
self.curl = pycurl.Curl()
85
81
abspath = self.abspath(relpath)
87
# pycurl needs plain ascii
88
83
if isinstance(abspath, unicode):
89
# XXX: HttpTransportBase.abspath should probably url-escape
90
# unicode characters if any in the path - domain name must be
92
84
abspath = abspath.encode('ascii')
93
85
self.curl.setopt(pycurl.URL, abspath)
94
## self.curl.setopt(pycurl.VERBOSE, 1)
95
self._set_curl_cache_headers()
86
self._set_curl_options(self.curl)
96
87
self.curl.setopt(pycurl.WRITEFUNCTION, sio.write)
97
88
self.curl.setopt(pycurl.NOBODY, 0)
99
89
self._curl_perform()
101
90
code = self.curl.getinfo(pycurl.HTTP_CODE)
103
92
raise NoSuchFile(abspath)
104
elif not 200 <= code <= 399:
105
98
raise TransportError('http error %d acccessing %s' %
106
99
(code, self.curl.getinfo(pycurl.EFFECTIVE_URL)))
111
def _set_curl_cache_headers(self):
101
def _set_curl_options(self, curl):
102
"""Set options for all requests"""
112
103
# There's no way in http/1.0 to say "must revalidate"; we don't want
113
104
# to force it to always retrieve. so just turn off the default Pragma
114
105
# provided by Curl.
115
106
headers = ['Cache-control: must-revalidate',
117
self.curl.setopt(pycurl.HTTPHEADER, headers)
108
## self.curl.setopt(pycurl.VERBOSE, 1)
109
curl.setopt(pycurl.HTTPHEADER, headers)
110
curl.setopt(pycurl.FOLLOWLOCATION, 1) # follow redirect responses
119
112
def _curl_perform(self):
120
113
"""Perform curl operation and translate exceptions."""