Skip to content

Add configurable MaximumReadableBytes via HttpResponseFormatterOptions - #166

Merged
adrianiftode merged 1 commit into
masterfrom
features/http-message-formatter-options
Oct 7, 2026
Merged

adrianiftode merged 1 commit into
masterfrom
features/http-message-formatter-options

Conversation

@adrianiftode

@adrianiftode adrianiftode commented Oct 6, 2026 •

Copy link
Copy Markdown
Owner

Closes #167

What

Makes the content truncation limit (MaximumReadableBytes) configurable, without breaking existing users:

  • Per call — new parameter object HttpResponseFormatterOptions on HttpMessageFormatter:
var formatted = response.Format(new HttpResponseFormatterOptions
{
    MaximumReadableBytes = 4 * 1024
});
  • Globally — new ResponseFormatterOptions on FluentAssertionsWebConfig / AwesomeAssertionsWebConfig, set the same way as the existing Serializer setting:
FluentAssertionsWebConfig.ResponseFormatterOptions = new HttpResponseFormatterOptions
{
    MaximumReadableBytes = 4 * 1024
};

Why

The limit was a hard-coded const (10 * 128 * 1024) in ContentFormatterOptions, so users had no way to print more (or less) of a large response in their assertion failure messages.

How

  • HttpResponseFormatterOptions is a public parameter object with MaximumReadableBytes (defaults to the previous const value, must be > 0).
  • The parameter is exposed as an additional Format overload rather than an optional parameter on the existing method, so the change is both source- and binary-compatible — response.Format() keeps working untouched.
  • The options are threaded through the formatting pipeline (Appender → ProcessorsRunner → content processors → ProcessorBase.AppendContentWithinLimits), including multipart parts.
  • HttpMessageFormatter itself keeps no global state. The global lives only in FluentAssertionsWebConfig (and AwesomeAssertionsWebConfig via the AAV link-compiled source) and is read by the HttpResponseMessageFormatter adapter when it renders assertion failure messages. The *.Web.Types projects now reference HttpMessageFormatter.
  • InternalServerErrorProcessor still bypasses the limit, exactly as before.

Tests

  • HttpMessageFormatter.Tests: truncation with a custom limit through Format(options), defaults unchanged, invalid values throw, plus processor-level coverage.
  • FluentAssertions.Web.FluentAssertionsWebConfig.Tests and AwesomeAssertions.Web.AwesomeAssertionsWebConfig.Tests: default value and the global option limiting the formatted failure message (save/restore via IDisposable, non-parallelized collection).

Full solution builds with 0 errors, all tests pass on net9.0/net10.0 for the FluentAssertions.Web, .v8 and AwesomeAssertions flavors, and dotnet pack succeeds. Docs updated in the package readme and the root readme.

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.

Allow configuring the MaximumReadableBytes limit used when formatting responses

1 participant