Jaahas.HttpRequestTransformer 3.0.1

dotnet add package Jaahas.HttpRequestTransformer --version 3.0.1                
NuGet\Install-Package Jaahas.HttpRequestTransformer -Version 3.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Jaahas.HttpRequestTransformer" Version="3.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Jaahas.HttpRequestTransformer --version 3.0.1                
#r "nuget: Jaahas.HttpRequestTransformer, 3.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Jaahas.HttpRequestTransformer as a Cake Addin
#addin nuget:?package=Jaahas.HttpRequestTransformer&version=3.0.1

// Install Jaahas.HttpRequestTransformer as a Cake Tool
#tool nuget:?package=Jaahas.HttpRequestTransformer&version=3.0.1                

About

Jaahas.HttpRequestTransformer defines delegating handlers for transforming HTTP requests and responses.

Transforming Requests and Responses via Delegates

The HttpRequestPipelineHandler delegating handler can be used to transform requests and responses via a delegate:

builder.Services.AddHttpClient("PipelineTransformer")
    .AddHttpMessageHandler(() => new HttpRequestPipelineHandler(async (request, next, cancellationToken) => {
        request.Headers.Add("X-CustomRequestHeader", Guid.NewGuid().ToString());
        var response = await next.Invoke(request, cancellationToken);
        response.Headers.Add("X-CustomResponseHeader", Guid.NewGuid().ToString());
        return response;
    }));

Compressing Outgoing Requests

Jaahas.HttpRequestTransformer provides delegating handlers that can compress outgoing requests (for example if you are sending a large file or other payload to a server that supports compressed request bodies).

GZip

The GZipCompressor delegating handler can be used to compress outgoing requests using GZip compression:

builder.Services.AddHttpClient("GZipCompressor")
    .AddHttpMessageHandler(() => new GZipCompressor());

The constructor also accepts an optional callback that can be used to determine whether a request should be compressed or not:

builder.Services.AddHttpClient("GZipCompressor")
    // Compress requests to specific routes
    .AddHttpMessageHandler(() => new GZipCompressor(callback: request => request.RequestUri.LocalPath.Contains("/api/upload"))));

Brotli

Brotli compression is not available when targeting .NET Framework.

The BrotliCompressor delegating handler can be used to compress outgoing requests using Brotli compression:

builder.Services.AddHttpClient("BrotliCompressor")
    .AddHttpMessageHandler(() => new BrotliCompressor());

The constructor also accepts an optional callback that can be used to determine whether a request should be compressed or not:

builder.Services.AddHttpClient("BrotliCompressor")
    // Compress requests to specific routes
    .AddHttpMessageHandler(() => new BrotliCompressor(callback: request => request.RequestUri.LocalPath.Contains("/api/upload")));

Creating Custom HTTP Request Pipelines

In most cases, you should use Microsoft.Extensions.Http to configure and create HTTP clients, especially for long-running applications that need to manage the lifecycle of HTTP message handlers. The HttpClientFactory class in this library is designed for simple use cases where dependency injection is not available.

The HttpClientFactory class can be used to simplify creation of HTTP clients and HTTP pipelines where one or more delegating handlers are required:

var httpClient = HttpClientFactory.Create(
    new HttpRequestPipelineHandler((request, next, cancellationToken) => {
        request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", GetToken());
        return next.Invoke(request, cancellationToken);
    }),
    new GZipCompressor());
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Jaahas.HttpRequestTransformer:

Package Downloads
IntelligentPlant.AppStoreConnect.Adapter.Http.Client

HTTP client for App Store Connect adapters.

IntelligentPlant.DataCore.HttpClient

Strongly-typed client for Intelligent Plant's Data Core API.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.1 20 2/26/2025
2.2.0 4,018 9/27/2021
2.1.0 375 6/9/2021
2.0.0 8,677 2/5/2021
1.1.0 369 2/5/2021
1.0.1 7,715 8/23/2019