Changeset db82911 in mod_gnutls


Ignore:
Timestamp:
Dec 2, 2019, 2:44:54 PM (11 months ago)
Author:
Fiona Klute <fiona.klute@…>
Branches:
master, proxy-ticket
Children:
0a16644
Parents:
4dfbedd
Message:

https-test-client.py: Make the filter function an optional argument

With this HTTPSubprocessConnection is generic again, supporting any
subprocess that communicates via stdin/stdout.

File:
1 edited

Legend:

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

    r4dfbedd rdb82911  
    2626class HTTPSubprocessConnection(HTTPConnection):
    2727    def __init__(self, command, host, port=None,
     28                 output_filter=None,
    2829                 timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
    2930                 blocksize=8192):
     
    4142        # (see exception doc)
    4243        self.set_tunnel = None
     44        # This method will be run in a separate process and filter the
     45        # stdout of self._sproc. Its arguments are self._sproc.stdout
     46        # and the socket back to the HTTP connection (write-only).
     47        self._output_filter = output_filter
     48        # output filter process
    4349        self._fproc = None
    4450
     
    4955
    5056        # TODO: Maybe capture stderr?
    51         self._sproc = subprocess.Popen(self.command, stdout=subprocess.PIPE,
    52                                        stdin=s_remote, close_fds=True,
    53                                        bufsize=0)
    54         self._fproc = Process(target=filter_cert_log,
    55                               args=(self._sproc.stdout, s_remote))
    56         self._fproc.start()
     57        if self._output_filter:
     58            self._sproc = subprocess.Popen(self.command, stdout=subprocess.PIPE,
     59                                           stdin=s_remote, close_fds=True,
     60                                           bufsize=0)
     61            self._fproc = Process(target=self._output_filter,
     62                                  args=(self._sproc.stdout, s_remote))
     63            self._fproc.start()
     64        else:
     65            self._sproc = subprocess.Popen(self.command, stdout=s_remote,
     66                                           stdin=s_remote, close_fds=True,
     67                                           bufsize=0)
    5768        s_remote.close()
    5869        self.sock = s_local
     
    7788        # filter process receives HUP on pipe when the subprocess
    7889        # terminates
    79         self._fproc.join()
     90        if self._fproc:
     91            self._fproc.join()
    8092
    8193        # close the connection in the super class, which also calls
     
    292304
    293305    conn = HTTPSubprocessConnection(command, args.host, port=args.port,
     306                                    output_filter=filter_cert_log,
    294307                                    timeout=6.0)
    295308
Note: See TracChangeset for help on using the changeset viewer.