r46776 - Apply 8188_2.patch
glyph-TA+aISz0psMTMxyoc4vAAJOcrHinNvQL0E9HWUfgJXw@public.gmane.org
| Newsgroups | gmane.comp.python.twisted.commits |
|---|---|
| Message-ID | <[email protected]> |
Author: glyph
Date: Fri Feb 12 00:31:01 2016
New Revision: 46776
Modified:
branches/h2-alpn-8188/twisted/web/http.py
branches/h2-alpn-8188/twisted/web/tap.py
branches/h2-alpn-8188/twisted/web/test/test_http.py
Log:
Apply 8188_2.patch
Modified: branches/h2-alpn-8188/twisted/web/http.py
==============================================================================
--- branches/h2-alpn-8188/twisted/web/http.py (original)
+++ branches/h2-alpn-8188/twisted/web/http.py Fri Feb 12 00:31:01 2016
@@ -102,6 +102,12 @@
from twisted.web.iweb import IRequest, IAccessLogFormatter
from twisted.web.http_headers import Headers
+try:
+ from twisted.web.http2 import H2Connection
+ H2_ENABLED = True
+except ImportError:
+ H2_ENABLED = False
+
from twisted.web._responses import (
SWITCHING,
Modified: branches/h2-alpn-8188/twisted/web/tap.py
==============================================================================
--- branches/h2-alpn-8188/twisted/web/tap.py (original)
+++ branches/h2-alpn-8188/twisted/web/tap.py Fri Feb 12 00:31:01 2016
@@ -10,7 +10,7 @@
import os
-from twisted.web import server, static, script, demo
+from twisted.web import server, static, script, demo, http
from twisted.internet import interfaces, reactor
from twisted.python import usage, reflect, threadpool
from twisted.python.compat import _PY3
@@ -249,10 +249,31 @@
personal.setServiceParent(s)
else:
if config['https']:
- from twisted.internet.ssl import DefaultOpenSSLContextFactory
- i = internet.SSLServer(int(config['https']), site,
- DefaultOpenSSLContextFactory(config['privkey'],
- config['certificate']))
+ from twisted.internet.ssl import CertificateOptions
+ from OpenSSL import crypto
+
+ with open(config['privkey'], 'rb') as f:
+ privateKey = crypto.load_privatekey(
+ crypto.FILETYPE_PEM, f.read()
+ )
+
+ with open(config['certificate'], 'rb') as f:
+ certificate = crypto.load_certificate(
+ crypto.FILETYPE_PEM, f.read()
+ )
+
+ acceptableProtocols = [b'http/1.1']
+ if http.H2_ENABLED:
+ acceptableProtocols.insert(0, b'h2')
+
+ i = internet.SSLServer(
+ int(config['https']),
+ site,
+ CertificateOptions(privateKey,
+ certificate,
+ acceptableProtocols=acceptableProtocols),
+ backlog=128
+ )
i.setServiceParent(s)
strports.service(config['port'], site).setServiceParent(s)
Modified: branches/h2-alpn-8188/twisted/web/test/test_http.py
==============================================================================
--- branches/h2-alpn-8188/twisted/web/test/test_http.py (original)
+++ branches/h2-alpn-8188/twisted/web/test/test_http.py Fri Feb 12 00:31:01 2016
@@ -2317,3 +2317,15 @@
"in Twisted 15.0.0; please use Twisted Names to "
"resolve hostnames instead")},
sub(["category", "message"], warnings[0]))
+
+
+
+class HTTP_2_Tests(unittest.TestCase):
+ """
+ Tests for the HTTP/2 exposure in L{twisted.web.http}.
+ """
+ def test_http2NotPresent(self):
+ """
+ HTTP/2 support is not available in Twisted.
+ """
+ self.assertFalse(http.H2_ENABLED)