r47175 - Merge dropped-factory-8272: Restore the factory being given to HTTPChannel
hawkowl-TA+aISz0psMTMxyoc4vAAJOcrHinNvQL0E9HWUfgJXw@public.gmane.org Tue, 5 Apr 2016 22:44:54 -0600 (MDT)
| Newsgroups | gmane.comp.python.twisted.commits |
|---|---|
| Message-ID | <[email protected]> |
Author: hawkowl
Date: Tue Apr 5 22:44:50 2016
New Revision: 47175
Added:
branches/release-16.1.1-8275/twisted/web/topfiles/8272.bugfix
Modified:
branches/release-16.1.1-8275/twisted/web/http.py
branches/release-16.1.1-8275/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: branches/release-16.1.1-8275/twisted/web/http.py
==============================================================================
--- branches/release-16.1.1-8275/twisted/web/http.py (original)
+++ branches/release-16.1.1-8275/twisted/web/http.py Tue Apr 5 22:44:50 2016
@@ -2010,6 +2010,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: branches/release-16.1.1-8275/twisted/web/test/test_http.py
==============================================================================
--- branches/release-16.1.1-8275/twisted/web/test/test_http.py (original)
+++ branches/release-16.1.1-8275/twisted/web/test/test_http.py Tue Apr 5 22:44:50 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
@@ -236,7 +237,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"
@@ -322,6 +327,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 HTTPLoopbackTests(unittest.TestCase):
@@ -2205,6 +2219,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())
+
+
class MultilineHeadersTests(unittest.TestCase):
"""