def _make_http_response(self, endpoint, request, specific_signer=None): body_params = request.get_body_params() if body_params: body = urllib.urlencode(body_params) request.set_content(body) request.set_content_type(format_type.APPLICATION_FORM) elif request.get_content( ) and "Content-Type" not in request.get_headers(): request.set_content_type(format_type.APPLICATION_OCTET_STREAM) method = request.get_method() signer = self._signer if specific_signer is None else specific_signer header, url = signer.sign(self.__region_id, request) if self.get_user_agent() is not None: header['User-Agent'] = self.get_user_agent() if header is None: header = {} header['x-sdk-client'] = 'python/2.0.0' protocol = request.get_protocol_type() response = HttpResponse(endpoint, url, method, header, protocol, request.get_content(), self._port, timeout=self._timeout) if body_params: body = urllib.urlencode(request.get_body_params()) response.set_content(body, "utf-8", format_type.APPLICATION_FORM) return response
def _make_http_response(self, endpoint, request, read_timeout, connect_timeout, specific_signer=None): body_params = request.get_body_params() if body_params: content_type = request.get_headers().get('Content-Type') if content_type and format_type.APPLICATION_JSON in content_type: body = json.dumps(body_params) request.set_content(body) elif content_type and format_type.APPLICATION_XML in content_type: body = aliyunsdkcore.utils.parameter_helper.to_xml(body_params) request.set_content(body) else: body = urlencode(body_params) request.set_content(body) request.set_content_type(format_type.APPLICATION_FORM) elif request.get_content( ) and "Content-Type" not in request.get_headers(): request.set_content_type(format_type.APPLICATION_OCTET_STREAM) method = request.get_method() if isinstance(request, CommonRequest): request.trans_to_acs_request() signer = self._signer if specific_signer is None else specific_signer header, url = signer.sign(self._region_id, request) base = self.user_agent_header() extra_agent = self.handle_extra_agent(request) default_agent = self.default_user_agent() user_agent = self.merge_user_agent(default_agent, extra_agent) for key, value in user_agent.items(): base += ' %s/%s' % (key, value) header['User-Agent'] = base header['x-sdk-client'] = 'python/2.0.0' protocol = request.get_protocol_type() response = HttpResponse(endpoint, url, method, header, protocol, request.get_content(), self._port, read_timeout=read_timeout, connect_timeout=connect_timeout, verify=self.get_verify(), session=self.session, proxy=self.proxy) if body_params: response.set_content(body, "utf-8", request.get_headers().get('Content-Type')) return response
def _make_http_response(self, endpoint, request, read_timeout, connect_timeout, specific_signer=None): body_params = request.get_body_params() if body_params: body = urlencode(body_params) request.set_content(body) request.set_content_type(format_type.APPLICATION_FORM) elif request.get_content(): if 'Content-Type' not in request.get_headers() or \ request.get_headers()['Content-Type'] == format_type.APPLICATION_FORM: request.set_content_type(format_type.APPLICATION_OCTET_STREAM) method = request.get_method() signer = self._signer if specific_signer is None else specific_signer header, url = signer.sign(self._region_id, request) base = self.user_agent_header() extra_agent = self.handle_extra_agent(request) default_agent = self.default_user_agent() user_agent = self.merge_user_agent(default_agent, extra_agent) for key, value in user_agent.items(): base += ' %s/%s' % (key, value) header['User-Agent'] = base header['x-sdk-client'] = 'python/2.0.0' protocol = request.get_protocol_type() response = HttpResponse(endpoint, url, method, header, protocol, request.get_content(), self._port, read_timeout=read_timeout, connect_timeout=connect_timeout, verify=self.get_verify()) if body_params: body = urlencode(request.get_body_params()) response.set_content(body, "utf-8", format_type.APPLICATION_FORM) return response