'Verify that if the response headers given by C{appHeaders} are passed
to the I{start_response} callable, then the response header lines given
by C{expectedHeaders} plus I{Server} and I{Date} header lines are
included in the response.'

def _headersTest(self, appHeaders, expectedHeaders):

    self.patch(http, 'datetimeToString', (lambda : 'Tuesday'))
    channel = DummyChannel()
    def applicationFactory():
        def application(environ, startResponse):
            startResponse('200    OK', appHeaders)
            return iter(())
        return application
    (d, requestFactory) = self.requestFactoryFactory()
    def cbRendered(ignored):
        response = channel.transport.written.getvalue()
        (headers, rest) = response.split('\r\n\r\n', 1)
        headerLines = headers.split('\r\n')[1:]
        headerLines.sort()
        allExpectedHeaders = (expectedHeaders + ['Date:    Tuesday', ('Server:    ' + version), 'Transfer-Encoding:    chunked'])
        allExpectedHeaders.sort()
        self.assertEqual(headerLines, allExpectedHeaders)
    d.addCallback(cbRendered)
    self.lowLevelRender(requestFactory, applicationFactory, (lambda : channel), 'GET', '1.1', [], [''], None, [])
    return d
