r47173 - Merge dropped-factory-8272: Restore the factory being given to HTTPChannel

hawkowl-TA+aISz0psMTMxyoc4vAAJOcrHinNvQL0E9HWUfgJXw@public.gmane.org Tue, 5 Apr 2016 22:32:25 -0600 (MDT)
Newsgroups gmane.comp.python.twisted.commits
Message-ID <[email protected]>
Author: hawkowl
Date: Tue Apr  5 22:32:20 2016
New Revision: 47173

Added:
   trunk/twisted/web/topfiles/8272.bugfix
Modified:
   trunk/twisted/web/http.py
   trunk/twisted/web/test/test_http.py

Log:
Merge dropped-factory-8272: Restore the factory being given to HTTPChannel

Author: hawkowl
Reviewer: lukasa
Fixes: #8272

Modified: trunk/twisted/web/http.py
==============================================================================
--- trunk/twisted/web/http.py	(original)
+++ trunk/twisted/web/http.py	Tue Apr  5 22:32:20 2016
@@ -2262,6 +2262,22 @@
 
 
     @property
+    def factory(self):
+        """
+        @see: L{HTTPChannel.factory}
+        """
+        return self._channel.factory
+
+
+    @factory.setter
+    def factory(self, value):
+        """
+        @see: L{HTTPChannel.factory}
+        """
+        self._channel.factory = value
+
+
+    @property
     def requestFactory(self):
         return self._channel.requestFactory
 

Modified: trunk/twisted/web/test/test_http.py
==============================================================================
--- trunk/twisted/web/test/test_http.py	(original)
+++ trunk/twisted/web/test/test_http.py	Tue Apr  5 22:32:20 2016
@@ -14,7 +14,8 @@
 except ImportError:
     from urllib.parse import urlparse, urlunsplit, clear_cache
 
-from twisted.python.compat import _PY3, iterbytes, networkString, unicode, intToBytes
+from twisted.python.compat import (_PY3, iterbytes, networkString, unicode,
+                                   intToBytes, NativeStringIO)
 from twisted.python.failure import Failure
 from twisted.trial import unittest
 from twisted.trial.unittest import TestCase
@@ -237,7 +238,11 @@
 
 
 
-class ProtocolNegotiationTests(unittest.TestCase):
+class GenericHTTPChannelTests(unittest.TestCase):
+    """
+    Tests for L{http._genericHTTPChannelProtocol}, a L{HTTPChannel}-alike which
+    can handle different HTTP protocol channels.
+    """
     requests = (
         b"GET / HTTP/1.1\r\n"
         b"Accept: text/html\r\n"
@@ -323,6 +328,15 @@
         )
 
 
+    def test_factory(self):
+        """
+        The C{factory} attribute is taken from the inner channel.
+        """
+        a = http._genericHTTPChannelProtocolFactory(b'')
+        a._channel.factory = b"Foo"
+        self.assertEqual(a.factory, b"Foo")
+
+
 
 class ResponseWriteOrderingTests(unittest.TestCase):
     requests = (
@@ -2326,6 +2340,36 @@
         self.assertEqual((None, existing), (req.producer, transport.producer))
 
 
+    def test_finishProducesLog(self):
+        """
+        L{http.Request.finish} will call the channel's factory to produce a log
+        message.
+        """
+        factory = http.HTTPFactory()
+        factory._logDateTime = "sometime"
+        factory._logDateTimeCall = True
+        factory.startFactory()
+        factory.logFile = NativeStringIO()
+        proto = factory.buildProtocol(None)
+
+        val = [
+            b"GET /path HTTP/1.1\r\n",
+            b"\r\n\r\n"
+        ]
+
+        trans = StringTransport()
+        proto.makeConnection(trans)
+
+        for x in val:
+            proto.dataReceived(x)
+
+        proto._channel.requests[0].finish()
+
+        # A log message should be written out
+        self.assertIn('sometime "GET /path HTTP/1.1"',
+                      factory.logFile.getvalue())
+
+
     def test_transportDeprecated(self):
         """
         L{http.Request.transport} will raise a L{DeprecationWarning} if