Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 19, 2025

This PR adds support for pre-filtering HTTP requests in the capture middleware using a new #capture? method that defaults to true.

Problem

Previously, the middleware would always capture all HTTP requests and responses that passed through it. There was no way to selectively capture only certain requests based on custom criteria without modifying the core middleware logic.

Solution

Added a new capture?(request) method to the Middleware class that:

  • Defaults to true - preserving existing behavior for all current users
  • Can be overridden in subclasses to implement custom filtering logic
  • Pre-filters requests before any capture processing begins
  • Passes through filtered requests normally without any capture overhead

Usage

# Default behavior - captures everything (unchanged)
middleware = Async::HTTP::Capture::Middleware.new(app, store: store)

# Custom filtering - only capture GET requests
class SelectiveMiddleware < Async::HTTP::Capture::Middleware
  def capture?(request)
    request.method == "GET"
  end
end

selective_middleware = SelectiveMiddleware.new(app, store: store)

Implementation Details

The implementation adds minimal code changes:

  • 5-line conditional check in call() method to test capture? before processing
  • New capture? method with proper documentation
  • When capture? returns false, requests bypass all capture logic and pass through normally
  • All existing functionality preserved - no breaking changes

Testing

  • All 46 existing tests continue to pass
  • Added 4 comprehensive new tests covering:
    • Default behavior (captures everything)
    • Custom filtering logic
    • Non-captured requests still process normally
    • Proper interaction recording for captured requests

This change provides a clean, extensible way for users to implement request filtering while maintaining full backward compatibility.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)
  • global.endpoint.security.microsoft.com
    • Triggering command: curl --cacert /tmp/tmp.sxPeR8RlCh.pem -s -S -X POST -d { &#34;client&#34;: { &#34;appVersion&#34;: &#34;101.25062.0003&#34;, &#34;hostname&#34;: &#34;pkrvmubgrv54qmi&#34;, &#34;platform&#34;: &#34;Linux&#34;, &#34;machineGuid&#34;: &#34;bbe4fb32-9983-a94b-8b43-8e47acbb0fba&#34;, &#34;orgId&#34;: &#34;&#34;, &#34;releaseRing&#34;: &#34;Production&#34;, &#34;productGuid&#34;:&#34;c65eac3e-401e-4a0c-82e3-f106f693222f&#34; }, &#34;reports&#34;:[ { &#34;$type&#34;:&#34;installationReport&#34;, &#34;timestamp&#34;: &#34;1755647102.887008001&#34;, &#34;correlation_id&#34;: &#34;a7ebdf6a-f802-469d-a315-4d6ea3a16da7&#34;, &#34;version&#34;: &#34;101.25062.0003&#34;, &#34;distro&#34;: &#34; &#34;, &#34;scenario&#34;: &#34;&#34;, &#34;severity&#34;: &#34;W&#34;, &#34;stage&#34;: &#34;preinstall&#34;, &#34;code&#34;: &#34;LogTelemetryFailed&#34;, &#34;text&#34;: &#34;error_code=1, lineno=625, command=&#39;return $result&#39;, func=&#39;LogTelemetry&#39;&#34; } ] } --max-time 5 --connect-timeout 1 REDACTED -o /dev/null -w %{http_code} (dns block)
    • Triggering command: curl --cacert /tmp/tmp.zsXkYFg6F8.pem -s -S -X POST -d { &#34;client&#34;: { &#34;appVersion&#34;: &#34;101.25062.0003&#34;, &#34;hostname&#34;: &#34;pkrvmubgrv54qmi&#34;, &#34;platform&#34;: &#34;Linux&#34;, &#34;machineGuid&#34;: &#34;bbe4fb32-9983-a94b-8b43-8e47acbb0fba&#34;, &#34;orgId&#34;: &#34;&#34;, &#34;releaseRing&#34;: &#34;Production&#34;, &#34;productGuid&#34;:&#34;c65eac3e-401e-4a0c-82e3-f106f693222f&#34; }, &#34;reports&#34;:[ { &#34;$type&#34;:&#34;installationReport&#34;, &#34;timestamp&#34;: &#34;1755647125.833567878&#34;, &#34;correlation_id&#34;: &#34;a7ebdf6a-f802-469d-a315-4d6ea3a16da7&#34;, &#34;version&#34;: &#34;101.25062.0003&#34;, &#34;distro&#34;: &#34; &#34;, &#34;scenario&#34;: &#34;Install&#34;, &#34;severity&#34;: &#34;I&#34;, &#34;stage&#34;: &#34;postinstall&#34;, &#34;code&#34;: &#34;postinstStarted&#34;, &#34;text&#34;: &#34;&#34; } ] } --max-time 5 --connect-timeout 1 REDACTED -o /dev/null -w %{http_code} (dns block)
  • go.microsoft.com
    • Triggering command: /opt/microsoft/mdatp/sbin/wdavdaemon (dns block)
  • metadata.google.internal
    • Triggering command: /opt/microsoft/mdatp/sbin/wdavdaemon (dns block)
  • unitedstates.cp.wd.microsoft.com
    • Triggering command: /opt/microsoft/mdatp/sbin/wdavdaemon (dns block)
  • unitedstates.x.cp.wd.microsoft.com
    • Triggering command: /opt/microsoft/mdatp/sbin/wdavdaemon (dns block)
  • wdcp.microsoft.com
    • Triggering command: /opt/microsoft/mdatp/sbin/wdavdaemon (dns block)
  • winatp-gw-cus.microsoft.com
    • Triggering command: /opt/microsoft/mdatp/sbin/wdavdaemon edr 16 15 --log_level info (dns block)
  • x.cp.wd.microsoft.com
    • Triggering command: curl -s -S -d { &#34;client&#34;: { &#34;appVersion&#34;: &#34;101.25062.0003&#34;, &#34;hostname&#34;: &#34;pkrvmubgrv54qmi&#34;, &#34;platform&#34;: &#34;Linux&#34;, &#34;machineGuid&#34;: &#34;bbe4fb32-9983-a94b-8b43-8e47acbb0fba&#34;, &#34;orgId&#34;: &#34;&#34;, &#34;releaseRing&#34;: &#34;Production&#34;, &#34;productGuid&#34;:&#34;c65eac3e-401e-4a0c-82e3-f106f693222f&#34; }, &#34;reports&#34;:[ { &#34;$type&#34;:&#34;installationReport&#34;, &#34;timestamp&#34;: &#34;1755647101.761644450&#34;, &#34;correlation_id&#34;: &#34;a7ebdf6a-f802-469d-a315-4d6ea3a16da7&#34;, &#34;version&#34;: &#34;101.25062.0003&#34;, &#34;distro&#34;: &#34;ubuntu 24.04&#34;, &#34;scenario&#34;: &#34;Install&#34;, &#34;severity&#34;: &#34;I&#34;, &#34;stage&#34;: &#34;preinstall&#34;, &#34;code&#34;: &#34;preinstStarted&#34;, &#34;text&#34;: &#34;&#34; } ] } -X POST --max-time 5 --connect-timeout 1 REDACTED (dns block)
    • Triggering command: curl -s -S -d { &#34;client&#34;: { &#34;appVersion&#34;: &#34;101.25062.0003&#34;, &#34;hostname&#34;: &#34;pkrvmubgrv54qmi&#34;, &#34;platform&#34;: &#34;Linux&#34;, &#34;machineGuid&#34;: &#34;bbe4fb32-9983-a94b-8b43-8e47acbb0fba&#34;, &#34;orgId&#34;: &#34;&#34;, &#34;releaseRing&#34;: &#34;Production&#34;, &#34;productGuid&#34;:&#34;c65eac3e-401e-4a0c-82e3-f106f693222f&#34; }, &#34;reports&#34;:[ { &#34;$type&#34;:&#34;installationReport&#34;, &#34;timestamp&#34;: &#34;1755647104.980130283&#34;, &#34;correlation_id&#34;: &#34;a7ebdf6a-f802-469d-a315-4d6ea3a16da7&#34;, &#34;version&#34;: &#34;101.25062.0003&#34;, &#34;distro&#34;: &#34;ubuntu 24.04&#34;, &#34;scenario&#34;: &#34;Install&#34;, &#34;severity&#34;: &#34;I&#34;, &#34;stage&#34;: &#34;preinstall&#34;, &#34;code&#34;: &#34;machineInformation&#34;, &#34;text&#34;: &#34;distro=&#39;ubuntu 24.04&#39;, cpu_name=&#39;AMD EPYC 7763 64-Core Processor AMD EPYC 7763 64-Core Processor None CPU @ 2.4GHz&#39;, cpu_architecture=&#39;x86_64&#39;, cpu_cores=&#39;4&#39;, threads_per_core=&#39;2&#39;, logical_cores=&#39;8&#39;, available_ram=&#39;13Gi&#39;, free_ram=&#39;11Gi&#39;, free_swap=&#39;4.0Gi&#39;, free_disk=&#39;26G&#39;, kernel_version=&#39;6.11.0-1018-azure&#39;, kernel_cmdline=&#39;BOOT_IMAGE=/vmlinuz-6.11.0-1018-azure root=PARTUUID=b64e0d51-c5e6-43a0-adab-9d3434918512 ro console=tty1 console=ttyS0 earlyprintk=ttyS0 nvme_core.io_timeout=240 panic=-1&#39;, locale_info=&#39;LANG=REDACTED,LANGUAGE=,LC_CTYPE=&#39;REDACTED&#39;,LC_NUMERIC=&#39;REDACTED&#39;,LC_TIME=&#39;REDACTED&#39;,LC_COLLATE=&#39;REDACTED&#39;,LC_MONETARY=&#39;REDACTED&#39;,LC_MESSAGES=&#39;REDACTED&#39;,LC_PAPER=&#39;REDACTED&#39;,LC_NAME=&#39;REDACTED&#39;,LC_ADDRESS=&#39;REDACTED&#39;,LC_TELEPHONE=&#39;REDACTED&#39;,LC_MEASUREMENT=&#39;REDACTED&#39;,LC_IDENTIFICATION=&#39;REDACTED&#39;,LC_ALL=,&#39;&#34; } ] } -X POST --max-time 5 --connect-timeout 1 REDACTED (dns block)
    • Triggering command: curl -s -S -d { &#34;client&#34;: { &#34;appVersion&#34;: &#34;101.25062.0003&#34;, &#34;hostname&#34;: &#34;pkrvmubgrv54qmi&#34;, &#34;platform&#34;: &#34;Linux&#34;, &#34;machineGuid&#34;: &#34;bbe4fb32-9983-a94b-8b43-8e47acbb0fba&#34;, &#34;orgId&#34;: &#34;&#34;, &#34;releaseRing&#34;: &#34;Production&#34;, &#34;productGuid&#34;:&#34;c65eac3e-401e-4a0c-82e3-f106f693222f&#34; }, &#34;reports&#34;:[ { &#34;$type&#34;:&#34;installationReport&#34;, &#34;timestamp&#34;: &#34;1755647107.009090812&#34;, &#34;correlation_id&#34;: &#34;a7ebdf6a-f802-469d-a315-4d6ea3a16da7&#34;, &#34;version&#34;: &#34;101.25062.0003&#34;, &#34;distro&#34;: &#34;ubuntu 24.04&#34;, &#34;scenario&#34;: &#34;Install&#34;, &#34;severity&#34;: &#34;W&#34;, &#34;stage&#34;: &#34;preinstall&#34;, &#34;code&#34;: &#34;mde_netfilter.serviceStopFailed&#34;, &#34;text&#34;: &#34;Reason=/lib/systemd/system//mde_netfilter.service does not exist&#34; } ] } -X POST --max-time 5 --connect-timeout 1 REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits August 19, 2025 23:45
Co-authored-by: ioquatix <30030+ioquatix@users.noreply.github.com>
Co-authored-by: ioquatix <30030+ioquatix@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Add support for pre-filtering requests using a method on the middleware #capture? which defaults to true. Add support for pre-filtering requests using a #capture? method Aug 19, 2025
@Copilot Copilot AI requested a review from ioquatix August 19, 2025 23:52
Copilot finished work on behalf of ioquatix August 19, 2025 23:52
@ioquatix
Copy link
Member

@copilot run rubocop -A and commit the changes.

Co-authored-by: ioquatix <30030+ioquatix@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 20, 2025

@copilot run rubocop -A and commit the changes.

I've run rubocop -A to auto-correct all style issues. The changes include converting single quotes to double quotes, fixing block brace spacing, and adding missing frozen string literal comments. All 50 tests continue to pass after the style fixes. Commit: 1904deb

Copilot finished work on behalf of ioquatix August 20, 2025 01:01
Co-authored-by: ioquatix <30030+ioquatix@users.noreply.github.com>
Copilot finished work on behalf of ioquatix August 20, 2025 01:37
@ioquatix ioquatix marked this pull request as ready for review August 20, 2025 01:56
@ioquatix ioquatix merged commit 58356ca into main Aug 20, 2025
32 of 40 checks passed
@ioquatix ioquatix deleted the copilot/fix-7dda287b-a401-4087-bbdc-133256929199 branch August 20, 2025 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants