Changeset 4dfbedd in mod_gnutls


Ignore:
Timestamp:
Dec 2, 2019, 2:32:34 PM (11 months ago)
Author:
Fiona Klute <fiona.klute@…>
Branches:
master, proxy-ticket
Children:
db82911
Parents:
d9b0936
Message:

https-test-client.py: Move filter out of HTTPSubprocessConnection class

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/https-test-client.py

    rd9b0936 r4dfbedd  
    1616# limitations under the License.
    1717
    18 import select
    1918import socket
    2019import subprocess
    21 import sys
    22 import traceback
    2320import yaml
    2421
     
    4643        self._fproc = None
    4744
    48     @classmethod
    49     def _filter(cls, in_stream, out_stream):
    50         import fcntl
    51         import os
    52         # This filters out a log line about loading client
    53         # certificates that is mistakenly sent to stdout. My fix has
    54         # been merged, but buggy binaries will probably be around for
    55         # a while.
    56         # https://gitlab.com/gnutls/gnutls/merge_requests/1125
    57         cert_log = b'Processed 1 client X.509 certificates...\n'
    58 
    59         # Set the input to non-blocking mode
    60         fd = in_stream.fileno()
    61         fl = fcntl.fcntl(fd, fcntl.F_GETFL)
    62         fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
    63 
    64         # The poll object allows waiting for events on non-blocking IO
    65         # channels.
    66         poller = select.poll()
    67         poller.register(fd)
    68 
    69         run_loop = True
    70         while run_loop:
    71             # The returned tuples are file descriptor and event, but
    72             # we're only listening on one stream anyway, so we don't
    73             # need to check it here.
    74             for x, event in poller.poll():
    75                 # Critical: "event" is a bitwise OR of the POLL* constants
    76                 if event & select.POLLIN or event & select.POLLPRI:
    77                     data = in_stream.read()
    78                     if cert_log in data:
    79                         data = data.replace(cert_log, b'')
    80                     out_stream.send(data)
    81                 if event & select.POLLHUP or event & select.POLLRDHUP:
    82                     # Stop the loop, but process any other events that
    83                     # might be in the list returned by poll() first.
    84                     run_loop = False
    85 
    86         in_stream.close()
    87         out_stream.close()
    88 
    8945    def connect(self):
    9046        s_local, s_remote = socket.socketpair(socket.AF_UNIX,
     
    9652                                       stdin=s_remote, close_fds=True,
    9753                                       bufsize=0)
    98         self._fproc = Process(target=HTTPSubprocessConnection._filter,
     54        self._fproc = Process(target=filter_cert_log,
    9955                              args=(self._sproc.stdout, s_remote))
    10056        self._fproc.start()
     
    230186
    231187
     188def filter_cert_log(in_stream, out_stream):
     189    import fcntl
     190    import os
     191    import select
     192    # This filters out a log line about loading client
     193    # certificates that is mistakenly sent to stdout. My fix has
     194    # been merged, but buggy binaries will probably be around for
     195    # a while.
     196    # https://gitlab.com/gnutls/gnutls/merge_requests/1125
     197    cert_log = b'Processed 1 client X.509 certificates...\n'
     198
     199    # Set the input to non-blocking mode
     200    fd = in_stream.fileno()
     201    fl = fcntl.fcntl(fd, fcntl.F_GETFL)
     202    fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
     203
     204    # The poll object allows waiting for events on non-blocking IO
     205    # channels.
     206    poller = select.poll()
     207    poller.register(fd)
     208
     209    run_loop = True
     210    while run_loop:
     211        # The returned tuples are file descriptor and event, but
     212        # we're only listening on one stream anyway, so we don't
     213        # need to check it here.
     214        for x, event in poller.poll():
     215            # Critical: "event" is a bitwise OR of the POLL* constants
     216            if event & select.POLLIN or event & select.POLLPRI:
     217                data = in_stream.read()
     218                if cert_log in data:
     219                    data = data.replace(cert_log, b'')
     220                out_stream.send(data)
     221            if event & select.POLLHUP or event & select.POLLRDHUP:
     222                # Stop the loop, but process any other events that
     223                # might be in the list returned by poll() first.
     224                run_loop = False
     225
     226    in_stream.close()
     227    out_stream.close()
     228
     229
     230
    232231def format_response(resp, body):
    233232    s = f'{resp.status} {resp.reason}\n'
Note: See TracChangeset for help on using the changeset viewer.