Skip to content

Hosting request adapter code deduplication - #499

Merged
Rodrigo Brandão (rodrigobr-msft) merged 3 commits into
mainfrom
users/robrandao/linter-hosting
Jul 24, 2026
Merged

Hosting request adapter code deduplication#499
Rodrigo Brandão (rodrigobr-msft) merged 3 commits into
mainfrom
users/robrandao/linter-hosting

Conversation

@rodrigobr-msft

Copy link
Copy Markdown
Contributor

This pull request refactors the FastApiRequestAdapter and AiohttpRequestAdapter classes to improve code organization and reusability. The adapter classes are moved from multiple locations into their dedicated modules, and all relevant imports are updated. Additionally, copyright headers are added to several files.

Adapter class refactoring and code organization:

  • Moved the FastApiRequestAdapter implementation from cloud_adapter.py and channel_service_route_table.py into a new dedicated module, _fastapi_request_adapter.py, and updated imports accordingly. [1] [2] [3]
  • Moved the AiohttpRequestAdapter implementation from cloud_adapter.py into a new dedicated module, _aiohttp_request_adapter.py, and updated imports accordingly. [1] [2]

Code style and documentation:

  • Added copyright and license headers to several files, including the new adapter modules and __init__.py. [1] [2] [3] [4] [5]

Type annotations:

  • Updated type annotations in the CloudAdapter constructor to use | None syntax for optional parameters.

Copilot AI review requested due to automatic review settings July 24, 2026 19:10
@rodrigobr-msft Rodrigo Brandão (rodrigobr-msft) changed the title Small hosting code tweaks Hosting request adapter code deduplication Jul 24, 2026
@rodrigobr-msft
Rodrigo Brandão (rodrigobr-msft) marked this pull request as ready for review July 24, 2026 19:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request refactors the hosting-layer request adapters for FastAPI and aiohttp by extracting framework-specific *RequestAdapter implementations into dedicated modules and updating call sites, while also standardizing file headers. This improves organization and reduces duplication across hosting adapters.

Changes:

  • Extracted FastApiRequestAdapter into fastapi/_fastapi_request_adapter.py and updated FastAPI imports/usages.
  • Extracted AiohttpRequestAdapter into aiohttp/_aiohttp_request_adapter.py and removed the in-file definition from the aiohttp cloud_adapter.
  • Added copyright/license headers to several FastAPI/aiohttp hosting modules.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/cloud_adapter.py Removes inline FastAPI request adapter and switches to the new dedicated module; updates optional type syntax.
libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/channel_service_route_table.py Replaces inline FastAPI adapter with import from the new shared module.
libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/_start_agent_process.py Adds copyright/license header.
libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/_fastapi_request_adapter.py Introduces dedicated FastAPI request adapter module.
libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/init.py Adds copyright/license header.
libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/cloud_adapter.py Removes inline aiohttp request adapter in preparation for using the new dedicated module.
libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/_start_agent_process.py Adds copyright/license header.
libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/_aiohttp_request_adapter.py Introduces dedicated aiohttp request adapter module.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings July 24, 2026 21:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 24, 2026 21:43
@rodrigobr-msft
Rodrigo Brandão (rodrigobr-msft) merged commit a7e12a1 into main Jul 24, 2026
10 of 11 checks passed
@rodrigobr-msft
Rodrigo Brandão (rodrigobr-msft) deleted the users/robrandao/linter-hosting branch July 24, 2026 21:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (2)

libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/_fastapi_request_adapter.py:22

  • HttpRequestProtocol.headers/json() are typed as dict[...], but this adapter currently returns framework-specific header objects and an unvalidated JSON payload. This breaks structural typing and can allow non-object JSON through until later validation. Consider normalizing headers into a plain dict (while preserving common header-case lookups) and enforcing that json() returns a JSON object.
    @property
    def headers(self):
        return self._request.headers

    async def json(self):
        return await self._request.json()

libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/_aiohttp_request_adapter.py:22

  • HttpRequestProtocol.headers/json() are typed as dict[...], but this adapter currently returns aiohttp's multi-dict headers object and an unvalidated JSON payload. This breaks structural typing and can allow non-object JSON through until later validation. Normalize headers into a plain dict (preserving common header-case lookups), enforce that json() returns a JSON object, and make get_path_param return a default value instead of raising KeyError.
    @property
    def headers(self):
        return self._request.headers

    async def json(self):
        return await self._request.json()

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.

3 participants