Esempio n. 1
0
    def __init__(self,
                 method=None,
                 url=None,
                 headers=None,
                 data=None,
                 params=None,
                 auth_path=None,
                 stream_output=False):

        # Default empty dicts for dict params.
        params = {} if params is None else params

        self.method = method
        self.url = url
        self.headers = HTTPHeaders()
        self.data = data
        self.params = params
        self.auth_path = auth_path
        self.stream_output = stream_output

        if headers is not None:
            for key, value in headers.items():
                self.headers[key] = value

        # This is a dictionary to hold information that is used when
        # processing the request. What is inside of ``context`` is open-ended.
        # For example, it may have a timestamp key that is used for holding
        # what the timestamp is when signing the request. Note that none
        # of the information that is inside of ``context`` is directly
        # sent over the wire; the information is only used to assist in
        # creating what is sent over the wire.
        self.context = {}
Esempio n. 2
0
 def __init__(self, *args, **kwargs):
     models.Request.__init__(self, *args, **kwargs)
     headers = HTTPHeaders()
     if self.headers is not None:
         for key, value in self.headers.items():
             headers[key] = value
     self.headers = headers
Esempio n. 3
0
 def __init__(self, *args, **kwargs):
     self.auth_path = None
     if 'auth_path' in kwargs:
         self.auth_path = kwargs['auth_path']
         del kwargs['auth_path']
     models.Request.__init__(self, *args, **kwargs)
     headers = HTTPHeaders()
     if self.headers is not None:
         for key, value in self.headers.items():
             headers[key] = value
     self.headers = headers
Esempio n. 4
0
 def headers_to_sign(self, request):
     """
     Select the headers from the request that need to be included
     in the StringToSign.
     """
     header_map = HTTPHeaders()
     split = urlsplit(request.url)
     for name, value in request.headers.items():
         lname = name.lower()
         header_map[lname] = value
     if 'host' not in header_map:
         header_map['host'] = split.netloc
     return header_map
Esempio n. 5
0
 def headers_to_sign(self, request):
     """
     Select the headers from the request that need to be included
     in the StringToSign.
     """
     header_map = HTTPHeaders()
     for name, value in request.headers.items():
         lname = name.lower()
         if lname not in SIGNED_HEADERS_BLACKLIST:
             header_map[lname] = value
     if 'host' not in header_map:
         header_map['host'] = self._canonical_host(request.url)
     return header_map
Esempio n. 6
0
 def headers_to_sign(self, request):
     """
     Select the headers from the request that need to be included
     in the StringToSign.
     """
     header_map = HTTPHeaders()
     for name, value in request.headers.items():
         lname = name.lower()
         if lname not in SIGNED_HEADERS_BLACKLIST:
             header_map[lname] = value
     if 'host' not in header_map:
         # TODO: We should set the host ourselves, instead of relying on our
         # HTTP client to set it for us.
         header_map['host'] = _host_from_url(request.url)
     return header_map
Esempio n. 7
0
 def headers_to_sign(self, request):
     """
     Select the headers from the request that need to be included
     in the StringToSign.
     """
     header_map = HTTPHeaders()
     for name, value in request.headers.items():
         lname = name.lower()
         if lname not in SIGNED_HEADERS_BLACKLIST:
             header_map[lname] = value
     if 'host' not in header_map:
         # Ensure we sign the lowercased version of the host, as that
         # is what will ultimately be sent on the wire.
         # TODO: We should set the host ourselves, instead of relying on our
         # HTTP client to set it for us.
         header_map['host'] = self._canonical_host(request.url).lower()
     return header_map
Esempio n. 8
0
 def __init__(self, *args, **kwargs):
     self.auth_path = None
     if 'auth_path' in kwargs:
         self.auth_path = kwargs['auth_path']
         del kwargs['auth_path']
     models.Request.__init__(self, *args, **kwargs)
     headers = HTTPHeaders()
     if self.headers is not None:
         for key, value in self.headers.items():
             headers[key] = value
     self.headers = headers
     # This is a dictionary to hold information that is used when
     # processing the request. What is inside of ``context`` is open-ended.
     # For example, it may have a timestamp key that is used for holding
     # what the timestamp is when signing the request. Note that none
     # of the information that is inside of ``context`` is directly
     # sent over the wire; the information is only used to assist in
     # creating what is sent over the wire.
     self.context = {}
Esempio n. 9
0
 def test_trims_leading_trailing_spaces(self):
     auth = self.create_signer()
     original = HTTPHeaders()
     original['foo'] = '  leading  and  trailing  '
     headers = auth.canonical_headers(original)
     self.assertEqual(headers, 'foo:leading and trailing')
Esempio n. 10
0
 def test_collapse_multiple_spaces(self):
     auth = self.create_signer()
     original = HTTPHeaders()
     original['foo'] = 'double  space'
     headers = auth.canonical_headers(original)
     self.assertEqual(headers, 'foo:double space')