-
Notifications
You must be signed in to change notification settings - Fork 4
Add support for capturing all requests #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the WalkthroughThis pull request introduces a new HTTP Request Catcher service built with Flask. The implementation includes a Flask application (app.py) that captures and provides access to HTTP requests through in-memory storage and multiple query endpoints. Supporting changes include Docker configuration to copy the app.py file into the container, README documentation describing the available API endpoints, and .gitignore patterns for Python cache files. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
Co-authored-by: abnegate <5857008+abnegate@users.noreply.github.com>
Co-authored-by: abnegate <5857008+abnegate@users.noreply.github.com>
|
@copilot Need the ability to fetch a specific request based on it's header/body values |
Co-authored-by: abnegate <5857008+abnegate@users.noreply.github.com>
Added
Multiple filters can be combined: |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
Dockerfile (2)
2-2: Python 3.6 reached end-of-life in December 2021 and no longer receives security updates.The base image uses Python 3.6, which is unsupported. Upgrade to a currently maintained version (Python 3.11 or later for support through 2027+, or at minimum Python 3.10 for support through October 2026) along with a newer Alpine version.
17-17: Upgrade Flask — CVE-2023-30861 vulnerability present.Flask 1.1.2 (released April 2020) is affected by CVE-2023-30861, a cache-poisoning and session cookie handling vulnerability. This version is no longer actively supported. Upgrade to Flask 2.2.5, 2.3.2, or later.
🤖 Fix all issues with AI agents
In @app.py:
- Around line 7-8: The global all_requests list can grow without bound; replace
it with a collections.deque configured with a maxlen pulled from configuration
(or an environment variable) to cap memory, e.g. all_requests =
deque(maxlen=MAX_REQUEST_HISTORY), keep last_request as-is, and update
clear_requests() to call all_requests.clear() and update find_request() to
iterate over the deque (iteration semantics are identical to a list); ensure
MAX_REQUEST_HISTORY is documented and defaulted to a reasonable value and that
any code that assumed list-specific methods is adjusted to deque-compatible
calls.
🧹 Nitpick comments (3)
app.py (3)
3-3: Unused import:environThe
environimport fromosis not used anywhere in the file.Proposed fix
-from os import environ
70-72: Unusedpathparameter is intentional.The
pathparameter is required by Flask's routing mechanism for the catch-all pattern but doesn't need to be used in the function body. The static analysis warning can be safely ignored, or you can prefix it with an underscore to indicate it's intentionally unused.Optional: prefix with underscore
-def catch(path): +def catch(_path):
36-54: Header normalization is repeated for each filter check.The lowercase header dictionary is rebuilt on every request in the loop. Consider extracting it once per request for efficiency.
Proposed optimization
for req in all_requests: match = True + req_headers_lower = {k.lower(): v for k, v in req['headers'].items()} for key, value in request.args.items(): if key.startswith('header_'): header_name = key[7:] # Remove 'header_' prefix - req_headers = {k.lower(): v for k, v in req['headers'].items()} - if req_headers.get(header_name.lower()) != value: + if req_headers_lower.get(header_name.lower()) != value: match = False break
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
.gitignoreDockerfileREADME.mdapp.py
🧰 Additional context used
🪛 Ruff (0.14.10)
app.py
72-72: Unused function argument: path
(ARG001)
88-88: Possible binding to all interfaces
(S104)
🔇 Additional comments (4)
.gitignore (1)
1-3: LGTM!Standard Python bytecode ignore patterns appropriate for the Flask application.
Dockerfile (1)
27-28: Intentional override of upstream app.py is clear.The ordering ensures the local
app.pyreplaces the upstream version. This approach works correctly for the intended behavior.app.py (1)
87-88: Binding to all interfaces is appropriate for Docker.The static analysis warning about binding to
0.0.0.0is a false positive in this context—it's required for the container to accept external connections.README.md (1)
31-75: Documentation is comprehensive and aligns with implementation.The API endpoint documentation is clear, includes practical examples, and accurately reflects the functionality implemented in
app.py.
|
@copilot In @app.py around lines 7 - 8, The global all_requests list can grow without |
Co-authored-by: abnegate <5857008+abnegate@users.noreply.github.com>
Implemented in commit 34ca91a. Changed |
|
@copilot Add tests covering all API routes and a github workflow that runs them |
Co-authored-by: abnegate <5857008+abnegate@users.noreply.github.com>
Added in commit ef1f96f: Tests (
GitHub Workflow ( |
Currently only the last request is stored, making it unusable for parallel test runs where multiple requests need to be captured and inspected.
Changes
app.py: New Flask app that stores all requests in a memory-capped deque/__all_requests__(GET) - Returns all captured requests/__find_request__(GET) - Find specific requests by header/body values/__clear__(POST/DELETE) - Clears request history for test isolation/__last_request__- Preserved for backward compatibilitycollections.dequewith configurablemaxlento prevent unbounded memory growthDockerfile: Copies localapp.pyover upstream versionREADME.md: Documents new API endpoints and environment variablestest_app.py: Comprehensive test suite with 28 tests covering all API routes.github/workflows/tests.yml: GitHub Actions workflow to run tests on push/PREnvironment Variables
MAX_REQUEST_HISTORYUsage
Testing
Tests cover:
/__last_request__endpoint/__all_requests__endpoint/__find_request__endpoint (method, body, header, URL filters)/__clear__endpointOriginal prompt
💡 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.
Summary by CodeRabbit
New Features
Documentation
Chores
✏️ Tip: You can customize this high-level summary in your review settings.