Skip to content

Expose HTTP response trailing headers - #2414

Open
Benziza wants to merge 2 commits into
restsharp:devfrom
Benziza:feat/response-trailing-headers
Open

Benziza wants to merge 2 commits into
restsharp:devfrom
Benziza:feat/response-trailing-headers

Conversation

@Benziza

@Benziza Benziza commented Sep 27, 2026 •

Copy link
Copy Markdown

Summary

  • add a separate TrailingHeaders collection to RestResponseBase
  • populate response trailers after the response content has been consumed on modern .NET targets
  • preserve compatibility with netstandard2.0 and .NET Framework by exposing an empty collection where HttpResponseMessage.TrailingHeaders is unavailable
  • verify multiple trailer values are preserved and not mixed into regular response headers

Closes #2413

Tests

  • dotnet test test/RestSharp.Tests/RestSharp.Tests.csproj -f net10.0 (274 passed)
  • dotnet build src/RestSharp/RestSharp.csproj (all library targets succeeded: netstandard2.0, net471, net48, net8.0, net9.0, net10.0)

The build reports existing NuGet vulnerability warnings for repository dependencies; there are no build errors.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Expose HTTP response trailing headers separately

✨ Enhancement 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Expose response trailers separately so callers can distinguish them from regular headers.
• Populate trailers after reading response content on modern .NET targets; default to an empty
 collection elsewhere.
• Test multiple trailer values and separation from regular headers.
Diagram

graph TD
    H["HTTP Handler"] --> M["HTTP Response"] --> B["Content Read"] --> T["Trailer Mapping"] --> R["Rest Response"]
    M --> N["Regular Headers"] --> R
Loading
High-Level Assessment

Keep the separate property and reuse the existing header conversion helper. Merging trailers into regular headers would lose their distinction, while conditional mapping preserves the public API on targets without HttpResponseMessage.TrailingHeaders.

Files changed (3) +45 / -1

Enhancement (2) +9 / -1
RestResponse.csMap available trailers into the completed response +4/-1

Map available trailers into the completed response

• Maps HttpResponseMessage.TrailingHeaders after reading response content on modern .NET targets. Older targets retain the base property's empty default.

src/RestSharp/Response/RestResponse.cs

RestResponseBase.csExpose a separate trailing-header collection +5/-0

Expose a separate trailing-header collection

• Adds a public TrailingHeaders collection initialized to empty, including on targets without trailer support.

src/RestSharp/Response/RestResponseBase.cs

Tests (1) +36 / -0
ResponseTrailerTests.csVerify trailer values remain separate from regular headers +36/-0

Verify trailer values remain separate from regular headers

• Uses a custom HTTP handler to supply multiple Digest values and another trailer. Verifies their mapping and confirms they do not appear among regular response headers.

test/RestSharp.Tests/ResponseTrailerTests.cs

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Content header separation goes untested ✓ Resolved 📎 Requirement gap ≡ Correctness
Description
Should_map_trailing_headers_separately_from_regular_headers checks that trailers are absent from
Headers but never checks ContentHeaders. When the handler returns its StringContent response,
a mapping that also puts Digest or X-Processing-Status into content headers would still pass
this test.
Code

test/RestSharp.Tests/ResponseTrailerTests.cs[23]

+        response.Headers.Should().NotContain(x => x.Name == "Digest" || x.Name == "X-Processing-Status");
Evidence
Rule 4 requires the test to verify separation from both initial and content headers. The new test
checks response.Headers but has no corresponding assertion for response.ContentHeaders.

Test trailer preservation and separation
test/RestSharp.Tests/ResponseTrailerTests.cs[15-24]
test/RestSharp.Tests/ResponseTrailerTests.cs[26-31]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The trailer regression test verifies separation from regular headers but not content headers.
## Fix Focus Areas
- test/RestSharp.Tests/ResponseTrailerTests.cs[22-24]
## Recommended Fix
Add an assertion that `response.ContentHeaders` contains neither `Digest` nor `X-Processing-Status`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can describe a rule in plain language on the Rules page and Qodo drafts it for you

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread test/RestSharp.Tests/ResponseTrailerTests.cs
@sonarqubecloud

Copy link
Copy Markdown

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose HTTP response trailers on RestResponse

1 participant