Skip to content

Add setting to compress HTTP request bodies#106

Merged
bgrainger merged 7 commits intoFacilityApi:masterfrom
bgrainger:compress-requests
Mar 28, 2025
Merged

Add setting to compress HTTP request bodies#106
bgrainger merged 7 commits intoFacilityApi:masterfrom
bgrainger:compress-requests

Conversation

@bgrainger
Copy link
Contributor

This opt-in setting will cause the HttpContent to be compressed with Content-Encoding: gzip.

This opt-in setting will cause the HttpContent to be compressed with "Content-Encoding: gzip".
@bgrainger bgrainger requested review from Copilot and ejball March 26, 2025 23:59
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces an opt-in setting to compress HTTP request bodies with gzip encoding. Key changes include:

  • Adding a new setting/property to control request compression across HttpClientService.
  • Implementing and integrating a helper method to compress HTTP content when enabled.
  • Updating related defaults, settings, and tests to support the new behavior.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/Facility.Core/Http/HttpClientService.cs Implements request compression logic and integrates it into the HTTP request pipeline.
src/Facility.Core/Http/HttpClientServiceDefaults.cs Adds a default property for compressing requests.
src/Facility.Core/Http/HttpClientServiceSettings.cs Introduces the ShouldCompressRequest property and propagates it to clones.
tests/Facility.Core.UnitTests/Http/HttpClientServiceSettingsTests.cs Updates tests to assign a compression callback for validation.

@bgrainger
Copy link
Contributor Author

Still needs a mechanism to set HttpClientServiceDefaults.CompressRequests = true in generated code.

/// </summary>
/// <remarks>Request bodies will be compressed with <c>Content-Encoding: gzip</c>. Even when this callback
/// returns <c>true</c>, the request may be sent uncompressed if compressing would make it larger.</remarks>
public Func<ServiceDto, bool>? ShouldCompressRequest { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm open to just going with public bool? CompressRequests { get; set; } if the delegate is YAGNI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't think of an actual reason to enable compression on a per-request basis, so happy to switch to the simpler API.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great! We can always add this if we need it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't think of an actual reason to enable compression on a per-request basis

I thought of one: the API might know that POST /v1/smallData always has a very small payload (and shouldn't be compressed), but that POST /v1/bigData is large and always should be. This could still be YAGNI, though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or that POST /v1/bigImage is already compressed and so shouldn't be compressed again.

@ejball
Copy link
Contributor

ejball commented Mar 27, 2025

Still needs a mechanism to set HttpClientServiceDefaults.CompressRequests = true in generated code.

A --compress-requests command-line option would be appropriate.

@bgrainger bgrainger requested a review from ejball March 28, 2025 16:21
@bgrainger
Copy link
Contributor Author

Multiple commits for code review; squash them when merging the PR.

@bgrainger bgrainger merged commit c044f27 into FacilityApi:master Mar 28, 2025
3 checks passed
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.

2 participants