Add support for pre-filtering requests using a #capture?
method
#1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds support for pre-filtering HTTP requests in the capture middleware using a new
#capture?
method that defaults totrue
.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 theMiddleware
class that:true
- preserving existing behavior for all current usersUsage
Implementation Details
The implementation adds minimal code changes:
call()
method to testcapture?
before processingcapture?
method with proper documentationcapture?
returnsfalse
, requests bypass all capture logic and pass through normallyTesting
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
/usr/lib/apt/methods/https
(dns block)global.endpoint.security.microsoft.com
curl --cacert /tmp/tmp.sxPeR8RlCh.pem -s -S -X POST -d { "client": { "appVersion": "101.25062.0003", "hostname": "pkrvmubgrv54qmi", "platform": "Linux", "machineGuid": "bbe4fb32-9983-a94b-8b43-8e47acbb0fba", "orgId": "", "releaseRing": "Production", "productGuid":"c65eac3e-401e-4a0c-82e3-f106f693222f" }, "reports":[ { "$type":"installationReport", "timestamp": "1755647102.887008001", "correlation_id": "a7ebdf6a-f802-469d-a315-4d6ea3a16da7", "version": "101.25062.0003", "distro": " ", "scenario": "", "severity": "W", "stage": "preinstall", "code": "LogTelemetryFailed", "text": "error_code=1, lineno=625, command='return $result', func='LogTelemetry'" } ] } --max-time 5 --connect-timeout 1 REDACTED -o /dev/null -w %{http_code}
(dns block)curl --cacert /tmp/tmp.zsXkYFg6F8.pem -s -S -X POST -d { "client": { "appVersion": "101.25062.0003", "hostname": "pkrvmubgrv54qmi", "platform": "Linux", "machineGuid": "bbe4fb32-9983-a94b-8b43-8e47acbb0fba", "orgId": "", "releaseRing": "Production", "productGuid":"c65eac3e-401e-4a0c-82e3-f106f693222f" }, "reports":[ { "$type":"installationReport", "timestamp": "1755647125.833567878", "correlation_id": "a7ebdf6a-f802-469d-a315-4d6ea3a16da7", "version": "101.25062.0003", "distro": " ", "scenario": "Install", "severity": "I", "stage": "postinstall", "code": "postinstStarted", "text": "" } ] } --max-time 5 --connect-timeout 1 REDACTED -o /dev/null -w %{http_code}
(dns block)go.microsoft.com
/opt/microsoft/mdatp/sbin/wdavdaemon
(dns block)metadata.google.internal
/opt/microsoft/mdatp/sbin/wdavdaemon
(dns block)unitedstates.cp.wd.microsoft.com
/opt/microsoft/mdatp/sbin/wdavdaemon
(dns block)unitedstates.x.cp.wd.microsoft.com
/opt/microsoft/mdatp/sbin/wdavdaemon
(dns block)wdcp.microsoft.com
/opt/microsoft/mdatp/sbin/wdavdaemon
(dns block)winatp-gw-cus.microsoft.com
/opt/microsoft/mdatp/sbin/wdavdaemon edr 16 15 --log_level info
(dns block)x.cp.wd.microsoft.com
curl -s -S -d { "client": { "appVersion": "101.25062.0003", "hostname": "pkrvmubgrv54qmi", "platform": "Linux", "machineGuid": "bbe4fb32-9983-a94b-8b43-8e47acbb0fba", "orgId": "", "releaseRing": "Production", "productGuid":"c65eac3e-401e-4a0c-82e3-f106f693222f" }, "reports":[ { "$type":"installationReport", "timestamp": "1755647101.761644450", "correlation_id": "a7ebdf6a-f802-469d-a315-4d6ea3a16da7", "version": "101.25062.0003", "distro": "ubuntu 24.04", "scenario": "Install", "severity": "I", "stage": "preinstall", "code": "preinstStarted", "text": "" } ] } -X POST --max-time 5 --connect-timeout 1 REDACTED
(dns block)curl -s -S -d { "client": { "appVersion": "101.25062.0003", "hostname": "pkrvmubgrv54qmi", "platform": "Linux", "machineGuid": "bbe4fb32-9983-a94b-8b43-8e47acbb0fba", "orgId": "", "releaseRing": "Production", "productGuid":"c65eac3e-401e-4a0c-82e3-f106f693222f" }, "reports":[ { "$type":"installationReport", "timestamp": "1755647104.980130283", "correlation_id": "a7ebdf6a-f802-469d-a315-4d6ea3a16da7", "version": "101.25062.0003", "distro": "ubuntu 24.04", "scenario": "Install", "severity": "I", "stage": "preinstall", "code": "machineInformation", "text": "distro='ubuntu 24.04', cpu_name='AMD EPYC 7763 64-Core Processor AMD EPYC 7763 64-Core Processor None CPU @ 2.4GHz', cpu_architecture='x86_64', cpu_cores='4', threads_per_core='2', logical_cores='8', available_ram='13Gi', free_ram='11Gi', free_swap='4.0Gi', free_disk='26G', kernel_version='6.11.0-1018-azure', kernel_cmdline='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', locale_info='LANG=REDACTED,LANGUAGE=,LC_CTYPE='REDACTED',LC_NUMERIC='REDACTED',LC_TIME='REDACTED',LC_COLLATE='REDACTED',LC_MONETARY='REDACTED',LC_MESSAGES='REDACTED',LC_PAPER='REDACTED',LC_NAME='REDACTED',LC_ADDRESS='REDACTED',LC_TELEPHONE='REDACTED',LC_MEASUREMENT='REDACTED',LC_IDENTIFICATION='REDACTED',LC_ALL=,'" } ] } -X POST --max-time 5 --connect-timeout 1 REDACTED
(dns block)curl -s -S -d { "client": { "appVersion": "101.25062.0003", "hostname": "pkrvmubgrv54qmi", "platform": "Linux", "machineGuid": "bbe4fb32-9983-a94b-8b43-8e47acbb0fba", "orgId": "", "releaseRing": "Production", "productGuid":"c65eac3e-401e-4a0c-82e3-f106f693222f" }, "reports":[ { "$type":"installationReport", "timestamp": "1755647107.009090812", "correlation_id": "a7ebdf6a-f802-469d-a315-4d6ea3a16da7", "version": "101.25062.0003", "distro": "ubuntu 24.04", "scenario": "Install", "severity": "W", "stage": "preinstall", "code": "mde_netfilter.serviceStopFailed", "text": "Reason=/lib/systemd/system//mde_netfilter.service does not exist" } ] } -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.