def test_remove(self): h = HttpHeaders() self.assertRaises(KeyError, h.remove, 'Non-Existent') h.add('Host', 'example.org') h.remove('Host') self.assertIsNone(h.get('Host'))
def test_get_is_case_insensitive(self): h = HttpHeaders() h.set('Cookie', 'a=1') h.add_pairs([('cookie', 'b=2'), ('COOKIE', 'c=3')]) h.add(u'CoOkIe', 'd=4') # note: unicode self.assertEqual('a=1', h.get(u'COOKIE')) self.assertEqual(['a=1', 'b=2', 'c=3', 'd=4'], list(h.get_values('Cookie')))
def test_unicode(self): # test adding unicode values in all the different ways h = HttpHeaders([('a', 'ሴ')]) self.assertEqual('ሴ', h.get('a')) h.set('b', '𦉘') self.assertEqual('𦉘', h.get('b')) h.add('c', '👁👄👁') self.assertEqual('👁👄👁', h.get('c')) h.add_pairs([('d', 'ⓤţḟ⁻❽')]) self.assertEqual('ⓤţḟ⁻❽', h.get('d'))
def test_remove_value(self): h = HttpHeaders() self.assertRaises(ValueError, h.remove_value, 'Non-Existent', 'Nope') # header with 1 value h.add('Host', 'example.org') self.assertRaises(ValueError, h.remove_value, 'Host', 'wrong-value') h.remove_value('Host', 'example.org') self.assertIsNone(h.get('Host')) # pluck out a duplicate value [1,2,2] -> [1,2] h.add_pairs([('Dupes', '1'), ('DUPES', '2'), ('dupes', '2')]) h.remove_value('Dupes', '2') self.assertEqual(['1', '2'], list(h.get_values('Dupes')))
def test_set(self): h = HttpHeaders() # create h.set('Host', 'example.org') self.assertEqual(['example.org'], list(h.get_values('Host'))) # replace h.set('Host', 'example2.org') self.assertEqual(['example2.org'], list(h.get_values('Host'))) # replace many h.add('Host', 'example3.org') h.add('Host', 'example4.org') h.set('Host', 'example5.org') self.assertEqual(['example5.org'], list(h.get_values('Host')))
def on_connection_completed(conn_future): try: connection = conn_future.result() headers = HttpHeaders() headers.add('host', self._gg_server_name) request = HttpRequest( method='GET', path='/greengrass/discover/thing/{}'.format(thing_name), headers=headers) http_stream = connection.request(request=request, on_body=on_incoming_body) http_stream.completion_future.add_done_callback( on_request_complete) except Exception as e: discovery['future'].set_exception(e)
def test_add_multi_values(self): h = HttpHeaders() h.add('Cookie', 'a=1') h.add('Cookie', 'b=2') self.assertEqual('a=1', h.get('Cookie')) self.assertEqual(['a=1', 'b=2'], list(h.get_values('Cookie')))
def test_add(self): h = HttpHeaders() h.add('Host', 'example.org') self.assertEqual('example.org', h.get('Host')) self.assertEqual(['example.org'], list(h.get_values('Host')))