镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Add HttpClient.QueryAsync overloads (#113522) - #136866

Open
Manish-1kumar wants to merge 2 commits into
dotnet:mainfrom
Manish-1kumar:users/Manish-1kumar/httpclient-query-async
Open

Manish-1kumar wants to merge 2 commits into
dotnet:mainfrom
Manish-1kumar:users/Manish-1kumar/httpclient-query-async

Conversation

@Manish-1kumar

@Manish-1kumar Manish-1kumar commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #113522

Summary

This PR implements the approved API proposal for adding QueryAsync overloads to HttpClient to support the RFC 10008 HTTP QUERY method:

namespace System.Net.Http;

public partial class HttpClient : HttpMessageInvoker
{
    public Task<HttpResponseMessage> QueryAsync([StringSyntax(Uri)] string? requestUri, HttpContent? content);
    public Task<HttpResponseMessage> QueryAsync([StringSyntax(Uri)] string? requestUri, HttpContent? content, CancellationToken cancellationToken);
    public Task<HttpResponseMessage> QueryAsync(Uri? requestUri, HttpContent? content);
    public Task<HttpResponseMessage> QueryAsync(Uri? requestUri, HttpContent? content, CancellationToken cancellationToken);
}

Changes

  • Implemented the 4 QueryAsync overloads in HttpClient.cs using HttpMethod.Query.
  • Updated reference assembly System.Net.Http.cs in alphabetical order following PutAsync.
  • Added unit tests in HttpClientTest.cs covering:
    • All 4 overloads verifying HttpMethod.Query, URI preservation, and content transmission.
    • Cancellation token triggering TaskCanceledException.
    • Disposed client validation throwing ObjectDisposedException.

Validation

  • Builds cleanly with 0 errors / 0 warnings (System.Net.Http, ref assembly, and System.Net.Http.Functional.Tests).
  • Targeted functional tests executed and passed (100% pass):
    • HttpClientTest.QueryAsync_Success
    • HttpClientTest.QueryAsync_Canceled_Throws
    • HttpClientTest.Dispose_UseQueryAfterDispose_Throws
    • HttpClientTest.Dispose_UseAfterDispose_Throws

Implements the four approved QueryAsync overloads on HttpClient following the approved API proposal for RFC 10008 QUERY method support:

- Task<HttpResponseMessage> QueryAsync(string?, HttpContent?)

- Task<HttpResponseMessage> QueryAsync(string?, HttpContent?, CancellationToken)

- Task<HttpResponseMessage> QueryAsync(Uri?, HttpContent?)

- Task<HttpResponseMessage> QueryAsync(Uri?, HttpContent?, CancellationToken)

Also updates the reference assembly and adds unit tests verifying method invocation, request headers/content preservation, cancellation, and ObjectDisposedException behavior.

Fixes dotnet#113522
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Nov 2, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@ManickaP
ManickaP requested a review from a team November 3, 2026 08:51

@ManickaP ManickaP left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> PutAsync([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("Uri")] string? requestUri, System.Net.Http.HttpContent? content, System.Threading.CancellationToken cancellationToken) { throw null; }
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> PutAsync(System.Uri? requestUri, System.Net.Http.HttpContent? content) { throw null; }
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> PutAsync(System.Uri? requestUri, System.Net.Http.HttpContent? content, System.Threading.CancellationToken cancellationToken) { throw null; }
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> QueryAsync([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("Uri")] string? requestUri, System.Net.Http.HttpContent? content) { throw null; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, confirmed! The QueryAsync declarations were generated following docs/coding-guidelines/updating-ref-source.md via dotnet msbuild /t:GenerateReferenceAssemblySource /p:TargetFramework=net12.0.

As recommended in the doc, unrelated GenAPI diff churn across pre-existing APIs (which causes CS8768/CS8769/CS8616 compiler errors on untouched types) was filtered out, keeping only the exact GenAPI-emitted declarations for the new QueryAsync overloads.

Both the reference assembly and implementation assembly build cleanly with 0 warnings/errors, and ApiCompat validation passes.

return SendAsync(request, cancellationToken);
}

public Task<HttpResponseMessage> QueryAsync([StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, HttpContent? content) =>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All new APIs should have /// docs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback! I've added XML documentation (///) to all four QueryAsync overloads, including summaries, parameter descriptions, return values, and applicable exceptions.

Verified the changes with a successful System.Net.Http build (0 warnings, 0 errors) and git diff --check.

No implementation or API signature changes were made.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Net.Http community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Proposal]: Add QUERY verb support to HttpClient

3 participants