def create_request_from_raw_request(raw_request): raw_request = raw_request.replace('http/1.1', 'HTTP/1.1') request = AWSRequest() raw = RawHTTPRequest(raw_request) if raw.error_code is not None: raise Exception(raw.error_message) request.method = raw.command datetime_now = datetime.datetime(2011, 9, 9, 23, 36) request.context['timestamp'] = datetime_now.strftime('%Y%m%dT%H%M%SZ') for key, val in raw.headers.items(): request.headers[key] = val request.data = raw.rfile.read() host = raw.headers.get('host', '') # For whatever reason, the BaseHTTPRequestHandler encodes # the first line of the response as 'iso-8859-1', # so we need decode this into utf-8. if isinstance(raw.path, six.text_type): raw.path = raw.path.encode('iso-8859-1').decode('utf-8') url = 'https://%s%s' % (host, raw.path) if '?' in url: split_url = urlsplit(url) params = dict(parse_qsl(split_url.query)) request.url = split_url.path request.params = params else: request.url = url return request
def create_request_from_raw_request(raw_request): raw_request = raw_request.replace('http/1.1', 'HTTP/1.1') request = AWSRequest() raw = RawHTTPRequest(raw_request) if raw.error_code is not None: raise Exception(raw.error_message) request.method = raw.command for key, val in raw.headers.items(): request.headers[key] = val request.data = raw.rfile.read().decode('utf-8') host = raw.headers.get('host', '') # For whatever reason, the BaseHTTPRequestHandler encodes # the first line of the response as 'iso-8859-1', # so we need decode this into utf-8. if isinstance(raw.path, six.text_type): raw.path = raw.path.encode('iso-8859-1').decode('utf-8') url = 'https://%s%s' % (host, raw.path) if '?' in url: split_url = urlsplit(url) params = dict(parse_qsl(split_url.query)) request.url = split_url.path request.params = params else: request.url = url return request
def test_operation_params_before_auth_params_in_params(self): request = AWSRequest() request.method = 'GET' request.url = 'https://ec2.us-east-1.amazonaws.com/' request.params = {'Action': 'MyOperation'} self.auth.add_auth(request) # Same situation, the params from request.param come before the # auth params in the query string. self.assertIn('?Action=MyOperation&X-Amz', request.url)
def test_get(self): request = AWSRequest() request.url = '/' request.method = 'GET' request.params = {'Foo': u'\u2713'} self.signer.add_auth(request) self.assertEqual(request.params['AWSAccessKeyId'], 'foo') self.assertEqual(request.params['Foo'], u'\u2713') self.assertEqual(request.params['Timestamp'], '2014-06-20T08:40:23Z') self.assertEqual(request.params['Signature'], u'Un97klqZCONP65bA1+Iv4H3AcB2I40I4DBvw5ZERFPw=') self.assertEqual(request.params['SignatureMethod'], 'HmacSHA256') self.assertEqual(request.params['SignatureVersion'], '2')