Changeset 4dfbedd in mod_gnutls
- Timestamp:
- Dec 2, 2019, 2:32:34 PM (3 years ago)
- Branches:
- asyncio, main, master, proxy-ticket
- Children:
- db82911
- Parents:
- d9b0936
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
test/https-test-client.py
rd9b0936 r4dfbedd 16 16 # limitations under the License. 17 17 18 import select19 18 import socket 20 19 import subprocess 21 import sys22 import traceback23 20 import yaml 24 21 … … 46 43 self._fproc = None 47 44 48 @classmethod49 def _filter(cls, in_stream, out_stream):50 import fcntl51 import os52 # This filters out a log line about loading client53 # certificates that is mistakenly sent to stdout. My fix has54 # been merged, but buggy binaries will probably be around for55 # a while.56 # https://gitlab.com/gnutls/gnutls/merge_requests/112557 cert_log = b'Processed 1 client X.509 certificates...\n'58 59 # Set the input to non-blocking mode60 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 IO65 # channels.66 poller = select.poll()67 poller.register(fd)68 69 run_loop = True70 while run_loop:71 # The returned tuples are file descriptor and event, but72 # we're only listening on one stream anyway, so we don't73 # need to check it here.74 for x, event in poller.poll():75 # Critical: "event" is a bitwise OR of the POLL* constants76 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 that83 # might be in the list returned by poll() first.84 run_loop = False85 86 in_stream.close()87 out_stream.close()88 89 45 def connect(self): 90 46 s_local, s_remote = socket.socketpair(socket.AF_UNIX, … … 96 52 stdin=s_remote, close_fds=True, 97 53 bufsize=0) 98 self._fproc = Process(target= HTTPSubprocessConnection._filter,54 self._fproc = Process(target=filter_cert_log, 99 55 args=(self._sproc.stdout, s_remote)) 100 56 self._fproc.start() … … 230 186 231 187 188 def 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 232 231 def format_response(resp, body): 233 232 s = f'{resp.status} {resp.reason}\n'
Note: See TracChangeset
for help on using the changeset viewer.