add SslProtocolVersion and HttpVersion#53
Conversation
WalkthroughAdds protocol selection: new enums ChangesProtocol Version Configuration
Sequence Diagram(s)sequenceDiagram
actor Caller
participant HttpClient
participant Handler
participant Server
Caller->>HttpClient: Send request (Options include SslProtocolVersion, HttpProtocolVersion)
HttpClient->>Handler: Handler enforces SslProtocols and version policy
Handler->>Server: TLS handshake (Tls1.2 / Tls1.3) and HTTP/2 or HTTP/1.1 negotiated
Server-->>Handler: Respond
Handler-->>HttpClient: Return response
HttpClient-->>Caller: Deliver response (status 200)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly Related PRs
Suggested Reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
Frends.HTTP.Request/Frends.HTTP.Request/Definitions/HttpVersion.cs (1)
6-16: ⚡ Quick win
HttpVersionconflicts withSystem.Net.HttpVersion— consider renaming the enum.The name
HttpVersionclashes with the BCL classSystem.Net.HttpVersion, forcing every file that imports bothFrends.HTTP.Request.DefinitionsandSystem.Net(orSystem.Net.Http) to use the fully-qualified form (Definitions.HttpVersion.Http20). This is already visible inExtensions.cs(Line 70) andUnitTests.cs(Line 468).Renaming the enum to
HttpProtocolVersion— which already matches theOptionsproperty name — would eliminate the ambiguity entirely.♻️ Proposed rename
- public enum HttpVersion + public enum HttpProtocolVersion { /// <summary> /// HTTP/1.1 - default, widely supported. /// </summary> Http11, /// <summary> /// HTTP/2 - multiplexed, requires server support. /// </summary> Http20 }Then in
Options.csthe property type and default already match:- [DefaultValue(HttpVersion.Http11)] - public HttpVersion HttpProtocolVersion { get; set; } = HttpVersion.Http11; + [DefaultValue(HttpProtocolVersion.Http11)] + public HttpProtocolVersion HttpProtocolVersion { get; set; } = HttpProtocolVersion.Http11;And in
Extensions.csthe switch arm no longer needs namespace qualification:- Definitions.HttpVersion.Http20 => System.Net.HttpVersion.Version20, + HttpProtocolVersion.Http20 => System.Net.HttpVersion.Version20,🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Frends.HTTP.Request/Frends.HTTP.Request/Definitions/HttpVersion.cs` around lines 6 - 16, Rename the enum named HttpVersion to HttpProtocolVersion (preserve the enum members Http11 and Http20 and their XML comments) and update all references: change the Options class property type (Options.ProtocolVersion or the existing property that currently uses HttpVersion) to use HttpProtocolVersion, update the switch in Extensions (remove fully-qualified System.Net disambiguation) and any usages in UnitTests to the new HttpProtocolVersion identifier so imports no longer conflict with System.Net.HttpVersion.Frends.HTTP.Request/Frends.HTTP.Request.Tests/UnitTests.cs (1)
460-474: ⚡ Quick winTest conflates TLS and HTTP-version configuration, making failures ambiguous.
The test sets both
SslProtocolVersion = Tls12And13andHttpProtocolVersion = Http20and then asserts only a200status code. This means:
- A failure could be caused by the
Http20+RequestVersionExactcombination (server negotiation) rather than the TLS setting — making it hard to tell which feature regressed.- Neither the TLS version actually negotiated nor the HTTP version used is verified; the
200assertion proves only that the server responded, not that the options were applied.Consider splitting into two focused tests and, if test isolation is a priority, capturing the
response.Versionfrom theHttpResponseMessageto assert the negotiated protocol.♻️ Suggested split
- [TestMethod] - public async Task RequestShouldSetTls12And13WhenConfigured() - { - var input = GetInputParams(url: $"{BasePath}/anything"); - var options = new Options - { - ConnectionTimeoutSeconds = 60, - SslProtocolVersion = SslVersion.Tls12And13, - HttpProtocolVersion = Definitions.HttpVersion.Http20 - }; - - var result = await HTTP.Request(input, options, CancellationToken.None); - - ClassicAssert.AreEqual(200, result.StatusCode); - } + [TestMethod] + public async Task RequestShouldSucceedWithTls12And13Configured() + { + var input = GetInputParams(url: $"{BasePath}/anything"); + var options = new Options + { + ConnectionTimeoutSeconds = 60, + SslProtocolVersion = SslVersion.Tls12And13, + }; + + var result = await HTTP.Request(input, options, CancellationToken.None); + + ClassicAssert.AreEqual(200, result.StatusCode); + } + + [TestMethod] + public async Task RequestShouldSucceedWithHttp20Configured() + { + var input = GetInputParams(url: $"{BasePath}/anything"); + var options = new Options + { + ConnectionTimeoutSeconds = 60, + HttpProtocolVersion = Definitions.HttpVersion.Http20 + }; + + var result = await HTTP.Request(input, options, CancellationToken.None); + + ClassicAssert.AreEqual(200, result.StatusCode); + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Frends.HTTP.Request/Frends.HTTP.Request.Tests/UnitTests.cs` around lines 460 - 474, Split the existing conflated test into two focused tests: keep RequestShouldSetTls12And13WhenConfigured and remove the HttpProtocolVersion assignment there (only set Options.SslProtocolVersion = SslVersion.Tls12And13) and assert the request succeeds and, if available on the result, capture and assert the negotiated TLS if your HTTP client exposes it; create a separate RequestShouldUseHttp2WhenConfigured test that sets Options.HttpProtocolVersion = Definitions.HttpVersion.Http20 (leave SslProtocolVersion default) and assert both success and that the response version was negotiated by checking the response message version (e.g. result.ResponseMessage.Version or the equivalent property on the returned result) so failures clearly indicate which feature regressed; use HTTP.Request, Options, SslProtocolVersion, HttpProtocolVersion, result.StatusCode and the response Version property to locate and implement the changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@Frends.HTTP.Request/CHANGELOG.md`:
- Around line 3-9: Update the 1.10.0 changelog entry: move the two bullets that
introduce SslProtocolVersion and HttpProtocolVersion from the "### Fixed"
section into a new or existing "### Added" section (referencing the names
SslProtocolVersion and HttpProtocolVersion), ensure their descriptions remain
unchanged, and remove the trailing empty "- " list item so there are no blank
bullets left under the 1.10.0 entry.
In `@Frends.HTTP.Request/Frends.HTTP.Request/Extensions.cs`:
- Around line 68-73: The code sets httpClient.DefaultVersionPolicy =
HttpVersionPolicy.RequestVersionExact unconditionally which breaks existing
default behavior and causes Http20 to fail fast without fallback; change the
logic in SetDefaultRequestHeadersBasedOnOptions (the block that switches on
options.HttpProtocolVersion and sets httpClient.DefaultRequestVersion) so that
DefaultVersionPolicy is set to RequestVersionExact only when
options.HttpProtocolVersion == Definitions.HttpVersion.Http20, and for the
Http11/default branch either leave DefaultVersionPolicy unset or explicitly set
it to HttpVersionPolicy.RequestVersionOrLower to preserve prior behavior; also
update any XML/doc comments for the Http20 enum member and CHANGELOG to note the
strict no-fallback semantics if desired.
---
Nitpick comments:
In `@Frends.HTTP.Request/Frends.HTTP.Request.Tests/UnitTests.cs`:
- Around line 460-474: Split the existing conflated test into two focused tests:
keep RequestShouldSetTls12And13WhenConfigured and remove the HttpProtocolVersion
assignment there (only set Options.SslProtocolVersion = SslVersion.Tls12And13)
and assert the request succeeds and, if available on the result, capture and
assert the negotiated TLS if your HTTP client exposes it; create a separate
RequestShouldUseHttp2WhenConfigured test that sets Options.HttpProtocolVersion =
Definitions.HttpVersion.Http20 (leave SslProtocolVersion default) and assert
both success and that the response version was negotiated by checking the
response message version (e.g. result.ResponseMessage.Version or the equivalent
property on the returned result) so failures clearly indicate which feature
regressed; use HTTP.Request, Options, SslProtocolVersion, HttpProtocolVersion,
result.StatusCode and the response Version property to locate and implement the
changes.
In `@Frends.HTTP.Request/Frends.HTTP.Request/Definitions/HttpVersion.cs`:
- Around line 6-16: Rename the enum named HttpVersion to HttpProtocolVersion
(preserve the enum members Http11 and Http20 and their XML comments) and update
all references: change the Options class property type (Options.ProtocolVersion
or the existing property that currently uses HttpVersion) to use
HttpProtocolVersion, update the switch in Extensions (remove fully-qualified
System.Net disambiguation) and any usages in UnitTests to the new
HttpProtocolVersion identifier so imports no longer conflict with
System.Net.HttpVersion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4bf11eed-88be-45c7-b421-6ae182c641be
📒 Files selected for processing (7)
Frends.HTTP.Request/CHANGELOG.mdFrends.HTTP.Request/Frends.HTTP.Request.Tests/UnitTests.csFrends.HTTP.Request/Frends.HTTP.Request/Definitions/HttpVersion.csFrends.HTTP.Request/Frends.HTTP.Request/Definitions/Options.csFrends.HTTP.Request/Frends.HTTP.Request/Definitions/SslVersion.csFrends.HTTP.Request/Frends.HTTP.Request/Extensions.csFrends.HTTP.Request/Frends.HTTP.Request/Frends.HTTP.Request.csproj
| httpClient.DefaultRequestHeaders.TryAddWithoutValidation("content-type", "application/json"); | ||
| httpClient.Timeout = TimeSpan.FromSeconds(Convert.ToDouble(options.ConnectionTimeoutSeconds)); | ||
|
|
||
| if (options.HttpProtocolVersion == Definitions.HttpVersion.Http20) |
There was a problem hiding this comment.
lets do it same switch approach which youve did for Ssl - as I understand for now You are assuming that Http11 is set by default but that might change in a future and a bug will come back to us
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@Frends.HTTP.Request/Frends.HTTP.Request/Request.cs`:
- Around line 257-258: The cache key construction in Request.cs currently
includes options.ThrowExceptionOnErrorResponse even though that flag is only
used later in Request() when processing responses and does not affect
HttpClientHandler/HttpClient creation; remove
options.ThrowExceptionOnErrorResponse from the concatenated cache key string
(leave AutomaticCookieHandling, SslProtocolVersion, and HttpProtocolVersion
intact) so the client cache is not split by this response-only flag, and ensure
any references to Request() and Extensions.cs behavior remain consistent.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a202ef1e-7bb6-4a8d-b775-493b7013a3c6
📒 Files selected for processing (1)
Frends.HTTP.Request/Frends.HTTP.Request/Request.cs
Please review my changes :)
Task Update PR template
Review Checklist
Summary by CodeRabbit
New Features
Tests
Chores