Make UriContent mediaType parameter optional with inference from URI file extension#7398
Merged
stephentoub merged 4 commits intomainfrom Mar 16, 2026
Merged
Conversation
…file extension Co-authored-by: stephentoub <[email protected]>
Co-authored-by: stephentoub <[email protected]>
Copilot created this pull request from a session on behalf of
stephentoub
March 16, 2026 17:34
View session
stephentoub
approved these changes
Mar 16, 2026
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/UriContent.cs
Outdated
Show resolved
Hide resolved
test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/UriContentTests.cs
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates UriContent to make mediaType optional, inferring it from the URI’s file extension (defaulting to application/octet-stream when unknown), and updates tests and API baselines accordingly.
Changes:
- Make
UriContentconstructors acceptstring? mediaType = nulland infer media type when omitted. - Add test coverage validating inference behavior and defaulting rules.
- Update the stable API baseline to reflect the optional/nullable
mediaTypeparameter.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/UriContentTests.cs | Updates ctor validation expectations and adds inference/defaulting tests. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Microsoft.Extensions.AI.Abstractions.json | Updates API baseline signatures for the modified constructors. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/UriContent.cs | Implements media type inference and introduces a default media type constant. |
You can also share your feedback on Copilot code review. Take the survey.
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/UriContent.cs
Outdated
Show resolved
Hide resolved
…fragment tests Co-authored-by: stephentoub <[email protected]>
…URIs with query strings and fragments Co-authored-by: stephentoub <[email protected]>
stephentoub
approved these changes
Mar 16, 2026
jozkee
approved these changes
Mar 16, 2026
jeffhandley
pushed a commit
to jeffhandley/extensions
that referenced
this pull request
Mar 17, 2026
…file extension (dotnet#7398) Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: stephentoub <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Updates
UriContent's constructors to make themediaTypeparameter optional. When not supplied ornullis passed, the media type is inferred from the file extension on the URI using the existingMediaTypeMap.GetMediaTypeutility. If there is no file extension or it's unknown,"application/octet-stream"is used as the default. Both absolute and relative URIs are supported for inference.Changes
UriContent(string, string?)andUriContent(Uri, string?)constructors to accept nullablemediaTypewith defaultnullInferMediaTypehelper that safely handles both absolute URIs (viaUri.AbsolutePath) and relative URIs (viaUri.OriginalStringwith query string/fragment stripping)DefaultMediaTypeconstant for"application/octet-stream"fallback (same pattern used inDataContent)Usage
Microsoft Reviewers: Open in CodeFlow
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.