'When a connection is made, L{HTTPPagerGetter} sends the headers from
its factory\'s C{headers} dict.  If I{Host} or I{Content-Length} is
present in this dict, the values are not sent, since they are sent with
special values before the C{headers} dict is processed.  If
I{User-Agent} is present in the dict, it overrides the value of the
C{agent} attribute of the factory.  If I{Cookie} is present in the
dict, its value is added to the values from the factory\'s C{cookies}
attribute.'

def test_earlyHeaders(self):

    factory = client.HTTPClientFactory('http://foo/bar', agent='foobar', cookies={'baz': 'quux'}, postdata='some    data', headers={'Host': 'example.net', 'User-Agent': 'fooble', 'Cookie': 'blah    blah', 'Content-Length': '12981', 'Useful': 'value'})
    transport = StringTransport()
    protocol = client.HTTPPageGetter()
    protocol.factory = factory
    protocol.makeConnection(transport)
    result = transport.value()
    for expectedHeader in ['Host:    example.net\r\n', 'User-Agent:    foobar\r\n', 'Content-Length:    9\r\n', 'Useful:    value\r\n', 'connection:    close\r\n', 'Cookie:    blah    blah;    baz=quux\r\n']:
        self.assertIn(expectedHeader, result)
