@@ -281,10 +281,7 @@ async def read_from_descriptors(self, r: Readables) -> bool:
281281 # only for non-https requests and when
282282 # tls interception is enabled
283283 if raw is not None :
284- if (
285- not self .request .is_https_tunnel
286- or self .tls_interception_enabled
287- ):
284+ if not self .request .is_https_tunnel or self ._tls_intercept_enabled :
288285 if self .response .is_complete :
289286 self .handle_pipeline_response (raw )
290287 else :
@@ -429,8 +426,7 @@ def on_client_data(self, raw: memoryview) -> None:
429426 # We also handle pipeline scenario for https proxy
430427 # requests is TLS interception is enabled.
431428 if self .request .is_complete and (
432- not self .request .is_https_tunnel or
433- self .tls_interception_enabled
429+ not self .request .is_https_tunnel or self ._tls_intercept_enabled
434430 ):
435431 if self .pipeline_request is not None and \
436432 self .pipeline_request .is_connection_upgrade :
@@ -474,6 +470,20 @@ def on_client_data(self, raw: memoryview) -> None:
474470 else :
475471 self .upstream .queue (raw )
476472
473+ @property
474+ def _tls_intercept_enabled (self ) -> bool :
475+ do_intercept = self .tls_interception_enabled
476+ if not do_intercept :
477+ return do_intercept
478+ # If enabled by flags, check if a plugin wants us to bypass
479+ # interception for this particular request
480+ for plugin in self .plugins .values ():
481+ do_intercept = plugin .do_intercept (self .request )
482+ # A plugin requested to not intercept the request
483+ if do_intercept is False :
484+ break
485+ return do_intercept
486+
477487 def on_request_complete (self ) -> Union [socket .socket , bool ]:
478488 self .emit_request_complete ()
479489
@@ -510,19 +520,8 @@ def on_request_complete(self) -> Union[socket.socket, bool]:
510520 if self .upstream :
511521 if self .request .is_https_tunnel :
512522 self .client .queue (PROXY_TUNNEL_ESTABLISHED_RESPONSE_PKT )
513- if self .tls_interception_enabled :
514- # Check if any plugin wants to
515- # disable interception even
516- # with flags available
517- do_intercept = True
518- for plugin in self .plugins .values ():
519- do_intercept = plugin .do_intercept (self .request )
520- # A plugin requested to not intercept
521- # the request
522- if do_intercept is False :
523- break
524- if do_intercept :
525- return self .intercept ()
523+ if self ._tls_intercept_enabled :
524+ return self .intercept ()
526525 # If an upstream server connection was established for http request,
527526 # queue the request for upstream server.
528527 else :
0 commit comments