MCPcopy Index your code
hub / github.com/python/cpython / test_putheader

Method test_putheader

Lib/test/test_httplib.py:233–265  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

231 )
232
233 def test_putheader(self):
234 conn = client.HTTPConnection('example.com')
235 conn.sock = FakeSocket(None)
236 conn.putrequest('GET','/')
237 conn.putheader('Content-length', 42)
238 self.assertIn(b'Content-length: 42', conn._buffer)
239
240 conn.putheader('Foo', ' bar ')
241 self.assertIn(b'Foo: bar ', conn._buffer)
242 conn.putheader('Bar', '\tbaz\t')
243 self.assertIn(b'Bar: \tbaz\t', conn._buffer)
244 conn.putheader('Authorization', 'Bearer mytoken')
245 self.assertIn(b'Authorization: Bearer mytoken', conn._buffer)
246 conn.putheader('IterHeader', 'IterA', 'IterB')
247 self.assertIn(b'IterHeader: IterA\r\n\tIterB', conn._buffer)
248 conn.putheader('LatinHeader', b'\xFF')
249 self.assertIn(b'LatinHeader: \xFF', conn._buffer)
250 conn.putheader('Utf8Header', b'\xc3\x80')
251 self.assertIn(b'Utf8Header: \xc3\x80', conn._buffer)
252 conn.putheader('C1-Control', b'next\x85line')
253 self.assertIn(b'C1-Control: next\x85line', conn._buffer)
254 conn.putheader('Embedded-Fold-Space', 'is\r\n allowed')
255 self.assertIn(b'Embedded-Fold-Space: is\r\n allowed', conn._buffer)
256 conn.putheader('Embedded-Fold-Tab', 'is\r\n\tallowed')
257 self.assertIn(b'Embedded-Fold-Tab: is\r\n\tallowed', conn._buffer)
258 conn.putheader('Key Space', 'value')
259 self.assertIn(b'Key Space: value', conn._buffer)
260 conn.putheader('KeySpace ', 'value')
261 self.assertIn(b'KeySpace : value', conn._buffer)
262 conn.putheader(b'Nonbreak\xa0Space', 'value')
263 self.assertIn(b'Nonbreak\xa0Space: value', conn._buffer)
264 conn.putheader(b'\xa0NonbreakSpace', 'value')
265 self.assertIn(b'\xa0NonbreakSpace: value', conn._buffer)
266
267 def test_ipv6host_header(self):
268 # Default host header on IPv6 transaction should be wrapped by [] if

Callers

nothing calls this directly

Calls 4

putrequestMethod · 0.95
putheaderMethod · 0.95
assertInMethod · 0.80
FakeSocketClass · 0.70

Tested by

no test coverage detected