Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add ExtraHeaderParameters and ExtraQueryParameters support to DownstreamApi#3413

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jmprieur merged 13 commits intomasterfromcopilot/fix-3387
Jul 16, 2025

Conversation

Copy link
Contributor

CopilotAI commentedJul 14, 2025
edited
Loading

This PR implements support forExtraHeaderParameters andExtraQueryParameters properties onDownstreamApiOptions to simplify adding custom headers and query parameters to downstream API requests.

Problem

Previously, developers had to use the complexCustomizeHttpRequestMessage delegate to add custom headers and query parameters to downstream API calls:

varresult=awaitdownstreamApi.GetForAppAsync<string>("Api",    options=>{options.CustomizeHttpRequestMessage= requestMessage=>{requestMessage.Headers.Add("OData-Version","4.0");// Query parameters would need manual URL manipulation};});

Solution

This PR adds support for the more convenientExtraHeaderParameters andExtraQueryParameters properties:

varresult=awaitdownstreamApi.GetForAppAsync<string>("Api",    options=>{options.ExtraHeaderParameters=newDictionary<string,string>{{"OData-Version","4.0"},{"X-Custom-Header","value"}};options.ExtraQueryParameters=newDictionary<string,string>{{"version","v2"},{"format","json"}};});

Implementation Details

Key Features

  • Reflection-based detection - Uses reflection to check if properties exist onDownstreamApiOptions for backward compatibility
  • Dual naming support - Supports both "ExtraHeaderParameters" and "ExtraHeadersParameters" naming conventions
  • Proper URL encoding - Query parameters are automatically URL-encoded usingUri.EscapeDataString
  • Maintains existing behavior - Works alongside existingCustomizeHttpRequestMessage delegate
  • Comprehensive test coverage - Tests for headers, query parameters, edge cases, and special characters

Technical Changes

  • AddedGetExtraHeaderParameters() andGetExtraQueryParameters() helper methods inDownstreamApi class
  • EnhancedUpdateRequestAsync() method to apply extra parameters beforeCustomizeHttpRequestMessage is called
  • Updated all target framework InternalAPI files with new method signatures
  • Created comprehensive test suite inExtraParametersTests.cs

Header Processing

  • Headers are added usingTryAddWithoutValidation to support custom header schemes
  • Applied beforeCustomizeHttpRequestMessage delegate, allowing for override
  • Empty or null dictionaries are safely ignored

Query Parameter Processing

  • Parameters are properly URL-encoded for safety
  • Correctly appends to existing query parameters in the URL
  • Handles special characters and spaces correctly

Testing

The implementation includes comprehensive tests covering:

  • Adding extra headers to requests
  • Adding extra query parameters with proper URL encoding
  • Appending to existing query parameters
  • Handling special characters and spaces
  • Edge cases with null/empty dictionaries
  • Alternate naming conventions (ExtraHeadersParameters vs ExtraHeaderParameters)

Backward Compatibility

The implementation uses reflection to detect if these properties exist onDownstreamApiOptions, ensuring full backward compatibility with different versions of the Microsoft.Identity.Abstractions package.

Dependencies

This feature assumes that theExtraHeaderParameters andExtraQueryParameters properties will be added toDownstreamApiOptions in the Microsoft.Identity.Abstractions package as mentioned in the related issue.

Fixes#3387.


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

CopilotAIand others added3 commitsJuly 14, 2025 20:51
…ueryParameters to DownstreamApiOptionsCo-authored-by: jmprieur <13203188+jmprieur@users.noreply.github.com>
…ownstreamApiCo-authored-by: jmprieur <13203188+jmprieur@users.noreply.github.com>
…tionCo-authored-by: jmprieur <13203188+jmprieur@users.noreply.github.com>
CopilotAI changed the title[WIP] [Feature Request] Send ExtraHeaderParameters and ExtraQueryParameters on DownstreamApisOptionsAdd ExtraHeaderParameters and ExtraQueryParameters support to DownstreamApiJul 14, 2025
CopilotAI requested a review fromjmprieurJuly 14, 2025 21:05
Copilot finished work on behalf ofjmprieurJuly 14, 2025 21:05
Copy link
Collaborator

@jmprieurjmprieur left a comment

Choose a reason for hiding this comment

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

A few suggestions for improvements

@jmprieur
Copy link
Collaborator

@copilot I've reviewed the PR and have suggestions for improvements

…rParameters and ExtraQueryParametersCo-authored-by: jmprieur <13203188+jmprieur@users.noreply.github.com>
CopilotAI requested a review fromjmprieurJuly 14, 2025 21:43
Copilot finished work on behalf ofjmprieurJuly 14, 2025 21:43
Copy link
ContributorAuthor

@copilot I've reviewed the PR and have suggestions for improvements

I've implemented the improvements by removing the unnecessary helper methodsGetExtraHeaderParameters() andGetExtraQueryParameters() that were just pass-through methods. The code now directly accesseseffectiveOptions.ExtraHeaderParameters andeffectiveOptions.ExtraQueryParameters properties, making it cleaner and more straightforward.

…ExtraQueryParameters accessCo-authored-by: jmprieur <13203188+jmprieur@users.noreply.github.com>
Copilot finished work on behalf ofjmprieurJuly 14, 2025 21:55
Co-authored-by: jmprieur <13203188+jmprieur@users.noreply.github.com>
CopilotAI requested a review fromjmprieurJuly 14, 2025 23:21
Copilot finished work on behalf ofjmprieurJuly 14, 2025 23:21
Copy link
Collaborator

@jmprieurjmprieur left a comment

Choose a reason for hiding this comment

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

@copilot I left a few comments

…Options directlyCo-authored-by: jmprieur <13203188+jmprieur@users.noreply.github.com>
CopilotAI requested a review fromjmprieurJuly 15, 2025 00:22
Copilot finished work on behalf ofjmprieurJuly 15, 2025 00:22
This was referencedNov 24, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@jennyf19jennyf19jennyf19 approved these changes

@keegan-carusokeegan-carusokeegan-caruso approved these changes

+1 more reviewer

@jmprieurjmprieurjmprieur approved these changes

Reviewers whose approvals may not affect merge requirements

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[Feature Request] Send ExtraHeaderParameters and ExtraQueryParameters on DownstreamApisOptions

4 participants

@jmprieur@jennyf19@keegan-caruso

[8]ページ先頭

©2009-2025 Movatter.jp