def connect(self, method, content_length, cookie):
try:
if self._scheme == 'http':
conn = httplib.HTTPConnection(self._server)
elif self._scheme == 'https':
# TODO(browne): This needs to be changed to use python requests
conn = httplib.HTTPSConnection(self._server) # nosec
else:
excep_msg = _("Invalid scheme: %s.") % self._scheme
LOG.error(excep_msg)
raise ValueError(excep_msg)
conn.putrequest(method, '/folder/%s?%s' % (self.path, self._query))
conn.putheader('User-Agent', constants.USER_AGENT)
conn.putheader('Content-Length', content_length)
conn.putheader('Cookie', cookie)
conn.endheaders()
LOG.debug("Created HTTP connection to transfer the file with "
"URL = %s.", str(self))
return conn
except (httplib.InvalidURL, httplib.CannotSendRequest,
httplib.CannotSendHeader) as excep:
excep_msg = _("Error occurred while creating HTTP connection "
"to write to file with URL = %s.") % str(self)
LOG.exception(excep_msg)
raise exceptions.VimConnectionException(excep_msg, excep)
评论列表
文章目录