Skip to content

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

Merged
MihaZupan merged 3 commits into
dotnet:mainfrom
Manish-1kumar:users/Manish-1kumar/httpclient-query-async
Nov 19, 2026
Merged

MihaZupan merged 3 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

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.

🟢 Approval recommended

No active review issues block the addition of the HttpClient.QueryAsync overloads.

No open issues 🎉

What changed in this PR

Adds four HttpClient.QueryAsync overloads for HTTP QUERY requests, matching the existing body-bearing request helpers and the API shape in #113522.

Changes:

  • Implements string and Uri overloads, with optional cancellation tokens, using HttpMethod.Query.
  • Adds matching declarations to the reference assembly.
  • Adds tests for overload behavior, request content and URI preservation, cancellation, and disposed clients.
File Description
src/​libraries/​System.Net.Http/​tests/​FunctionalTests/​HttpClientTest.cs Adds QUERY success, cancellation, and disposal tests.
src/​libraries/​System.Net.Http/​src/​System/​Net/​Http/​HttpClient.cs Implements and documents the four QueryAsync overloads.
src/​libraries/​System.Net.Http/​ref/​System.Net.Http.cs Exposes the overloads in the public reference API.

Review effort: Balanced

@MihaZupan MihaZupan added this to the 12.0.0 milestone Nov 14, 2026
Apply review suggestion to align the QueryAsync XML documentation with the
other HttpClient request helpers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@MihaZupan
MihaZupan merged commit db341b0 into dotnet:main Nov 19, 2026
67 of 69 checks passed
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

4 participants