def _add_generic_headers(self, http_method, uri, request_headers, context): """ Adds the necessary headers to the given list of headers. This includes the authorization header, which uses other headers, so when you need to override this method, make sure to call super.addGenericHeaders at the end of your overridden method. """ # add server meta info header request_headers.extend( self.__session.meta_data_provider.meta_data_headers) # add date header request_headers.append( RequestHeader("Date", self._get_header_date_string())) if context is not None and context.idempotence_key is not None: # add context specific headers request_headers.append( RequestHeader("X-GCS-Idempotence-Key", context.idempotence_key)) # add signature authenticator = self.__session.authenticator authentication_signature = \ authenticator.create_simple_authentication_signature( http_method, uri, request_headers) request_headers.append(RequestHeader("Authorization", authentication_signature))
def _put_with_binary_response(self, relative_path, request_headers, request_parameters, request_body, context): connection = self.__session.connection if request_parameters is None: request_parameter_list = None else: request_parameter_list = request_parameters.to_request_parameters() uri = self._to_absolute_uri(relative_path, request_parameter_list) if request_headers is None: request_headers = [] body = None if isinstance(request_body, MultipartFormDataObject): request_headers.append(RequestHeader("Content-Type", request_body.content_type)) body = request_body elif isinstance(request_body, MultipartFormDataRequest): multipart = request_body.to_multipart_form_data_object() request_headers.append(RequestHeader("Content-Type", multipart.content_type)) body = multipart elif request_body is not None: request_headers.append(RequestHeader("Content-Type", "application/json")) body = self.__marshaller.marshal(request_body) self._add_generic_headers("PUT", uri, request_headers, context) return connection.put(uri, request_headers, body)
def __init__(self, integrator, shopping_cart_extension=None, additional_request_headers=()): MetaDataProvider.__validate_additional_request_headers( additional_request_headers) for i in additional_request_headers: i.name = re.sub(r'\r?\n(?:(?![\r\n])\s)*', " ", i.name) i.name = i.name.strip() i.value = re.sub(r'\r?\n(?:(?![\r\n])\s)*', " ", i.value) i.value = i.value.strip() server_meta_info = self.ServerMetaInfo() server_meta_info.platform_identifier = self._platform_identifier server_meta_info.sdk_identifier = self._sdk_identifier server_meta_info.sdk_creator = "Ingenico" server_meta_info.integrator = integrator server_meta_info.shopping_cart_extension = shopping_cart_extension server_meta_info_string = DefaultMarshaller.INSTANCE().marshal( server_meta_info) server_meta_info_header = RequestHeader( self.__SERVER_META_INFO_HEADER, b64encode(server_meta_info_string.encode('utf-8'))) if not additional_request_headers: self.__meta_data_headers = tuple([server_meta_info_header]) else: request_headers = [server_meta_info_header] request_headers.extend(additional_request_headers) self.__meta_data_headers = tuple(request_headers)
def _client_headers(self): if self._client_meta_info is not None: client_headers = [ RequestHeader("X-GCS-ClientMetaInfo", self._client_meta_info) ] return client_headers else: return None
def fetch(_request_header: RequestHeader): # prepare the session object to store all session headers requests.Session() # get the target url url = _request_header.getRequestUrl() # take the RequestHeader object and put all the headers into the session [ session.headers.update(header_dict) for header_dict in _request_header.to_list() ] # send the request session_response = session.get(url) fetch_response = FetchResponse() fetch_response.set_request_header(_request_header) fetch_response.set_response_header(session_response.headers) fech_response.set_response_body(session_response.body) return fetch_response
def _put(self, relative_path, request_headers, request_parameters, request_body, context): if request_parameters is None: request_parameter_list = None else: request_parameter_list = request_parameters.to_request_parameters() uri = self._to_absolute_uri(relative_path, request_parameter_list) if request_headers is None: request_headers = [] body = None if request_body is not None: request_headers.append( RequestHeader("Content-Type", "application/json")) body = self.__marshaller.marshal(request_body) self._add_generic_headers("PUT", uri, request_headers, context) return self.connection.put(uri, request_headers, body)