File: factory.rst

package info (click to toggle)
twisted 25.5.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,560 kB
  • sloc: python: 203,171; makefile: 200; sh: 92; javascript: 36; xml: 31
file content (62 lines) | stat: -rw-r--r-- 1,562 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

:LastChangedDate: $LastChangedDate$
:LastChangedRevision: $LastChangedRevision$
:LastChangedBy: $LastChangedBy$

The Evolution of Finger: using a single factory for multiple protocols
======================================================================






Introduction
------------



This is the eighth part of the Twisted tutorial :doc:`Twisted from Scratch, or The Evolution of Finger <index>` .




In this part, we add HTTPS support to our web frontend, showing how to have a
single factory listen on multiple ports. More information on using SSL in
Twisted can be found in the :doc:`SSL howto <../ssl>` .





Support HTTPS
-------------



All we need to do to code an HTTPS site is just write a context factory (in
this case, which loads the certificate from a certain file) and then use the
``twisted.internet.endpoints.serverFromString`` method to build a SSL endpoint.
Note that one factory (in this case, a site) can listen on multiple ports with
multiple protocols.

Of course, this endpoint doesn't work without a TLS certificate and a private
key. You'll need to create a self-signed cert and key. This will obviously not
be trusted by your web browser, so you'll see a warning when you connect. In
this case, don't worry: you're not at risk.

To create a certificate and key that can be used by this tutorial, run the
following:

.. code-block:: bash

    openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365





:download:`finger22.py <listings/finger/finger22.py>`

.. literalinclude:: listings/finger/finger22.py