Audit.HttpClient 25.0.4

dotnet add package Audit.HttpClient --version 25.0.4
NuGet\Install-Package Audit.HttpClient -Version 25.0.4
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="Audit.HttpClient" Version="25.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Audit.HttpClient --version 25.0.4
#r "nuget: Audit.HttpClient, 25.0.4"
#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 Audit.HttpClient as a Cake Addin
#addin nuget:?package=Audit.HttpClient&version=25.0.4

// Install Audit.HttpClient as a Cake Tool
#tool nuget:?package=Audit.HttpClient&version=25.0.4

Audit.HttpClient

HttpClient audit extension for Audit.NET library.

Generate Audit Logs by intercepting HttpClient REST calls. Audit.HttpClient provides the infrastructure to create audit logs for an instance of HttpClient class.

It relies on a message handler to incercept the calls to HttpClient methods.

Install

NuGet Package

To install the package run the following command on the Package Manager Console:

PM> Install-Package Audit.HttpClient

NuGet Status NuGet Count

Usage

To enable the audit log for HttpClient, you have to set an AuditHttpClientHandler as a message handler for the HttpClient instance being audited.

This can be done in different ways:

  • Call the factory provided by Audit.Http.ClientFactory.Create() method to get a new audit-enabled instance of HttpClient:
var httpClient = Audit.Http.ClientFactory.Create(_ => _
    .IncludeRequestBody()
    .IncludeResponseHeaders()
    .FilterByRequest(req => req.Method.Method == "GET"));

The ClientFactory.Create method is just a shortcut to create a new HttpClient with a custom AuditHttpClientHandler as its message handler.

  • If you use ASP .NET dependency injection / HttpClientFactory, you can add the message handler with the extension method AddAuditHandler() on your startup:
using Audit.Http;

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddHttpClient("GitHub", c =>
        {
            c.BaseAddress = new Uri("https://api.github.com/");
        })
        .AddAuditHandler(audit => audit
            .IncludeRequestBody()
            .IncludeResponseHeaders());
    }
}

Note: AddAuditHandler(config) is a shortcut for AddHttpMessageHandler(() => new AuditHttpClientHandler(config))

  • You can also create an audited HttpClient passing the handler to its constructor:
var httpClient = new HttpClient(new AuditHttpClientHandler(_ => _
    .IncludeRequestBody()
    .IncludeResponseHeaders());

Each method call on the audited HttpClient instances will generate an Audit Event.

Configuration

Output

The audit events are stored using a Data Provider. You can use one of the available data providers or implement your own. Please refer to the data providers section on Audit.NET documentation.

Settings

The AuditHttpClientHandler class allows to configure the following settings:

  • RequestFilter / FilterByRequest: Set a filter function to determine which events to log depending on the request message. By default all events are logged.
  • ResponseFilter / FilterByResponse: Set a filter function to determine which events to log depending on the response message. By default all events are logged.
  • EventType: A string that identifies the event type. Default is "{verb} {url}". It can contain the following placeholders:
    • {verb}: Replaced by the Http Verb (GET, POST, ...)
    • {url}: Replaced by the request URL
  • IncludeRequestHeaders: Specifies whether the HTTP Request headers should be included on the audit output. Default is false.
  • IncludeResponseHeaders: Specifies whether the HTTP Response headers should be included on the audit output. Default is false.
  • IncludeContentHeaders: Specifies whether the HTTP Content headers should be included on the audit output. Default is false.
  • IncludeRequestBody: Specifies whether the HTTP Request body should be included on the audit output. Default is false.
  • IncludeResponseBody: Specifies whether the HTTP Response body should be included on the audit output. Default is false.
  • CreationPolicy: Allows to set a specific event creation policy. By default the globally configured creation policy is used. See Audit.NET Event Creation Policy section for more information.
  • AuditDataProvider: Allows to set a specific audit data provider. By default the globally configured data provider is used. See Audit.NET Data Providers section for more information.
  • AuditScopeFactory: Allows to set a specific audit scope factory. By default the general AuditScopeFactory is used.

Output Details

The following table describes the Audit.HttpClient output fields:

HttpAction

Describes an operation call event

Field Name Type Description
Method string HTTP rest method
Url string Request URL
Version string Http client version
Exception string Exception details when an exception is thrown
Request Request Request audit information
Response Response Response audit information

Request

Describes a HTTP request

Field Name Type Description
QueryString string Query string portion of the request URL
Scheme string Request scheme (http, https)
Path string Path portion of the request URL
Headers Dictionary Request headers
Content Content Request content

Response

Describes a HTTP response

Field Name Type Description
StatusCode int Response HTTP status code
Status string String representation of the response status code
Reason string Response status reason phrase
IsSuccess bool Indicates if the HTTP response was successful.
Headers Dictionary Request headers
Content Content Request content

Content

Describes the content of a HTTP request or response

Field Name Type Description
Body string Response body content decoded as a string
Headers Dictionary Content headers

Output Sample

{
	"EventType": "GET http://google.com/doesnotexists",
	"Environment": {
		"UserName": "Federico",
		"MachineName": "FEDE",
		"DomainName": "FEDE",
		"Culture": "en-US"
	},
	"StartDate": "2019-05-21T23:18:38.3251378Z",
	"EndDate": "2019-05-21T23:18:40.4623427Z",
	"Duration": 2137,
	"Action": {
		"Method": "GET",
		"Url": "http://google.com/doesnotexists",
		"Version": "1.1",
		"Request": {
			"QueryString": "",
			"Scheme": "http",
			"Path": "/doesnotexists",
			"Headers": {
				
			}
		},
		"Response": {
			"Headers": {
				"Date": "Tue, 21 May 2019 23:18:19 GMT",
				"Referrer-Policy": "no-referrer"
			},
			"Content": {
				"Body": "<!DOCTYPE html>\n<html lang=en>\n  <meta charset=utf-8>\n ....",
				"Headers": {
					"Content-Length": "1574",
					"Content-Type": "text/html; charset=UTF-8"
				}
			},
			"StatusCode": 404,
			"Status": "NotFound",
			"Reason": "Not Found",
			"IsSuccess": false
		}
	}
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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. 
.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 net461 was computed.  net462 is compatible.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
25.0.4 85 3/24/2024
25.0.3 197 3/13/2024
25.0.2 103 3/12/2024
25.0.1 199 2/28/2024
25.0.0 212 2/16/2024
24.0.1 411 2/12/2024
24.0.0 182 2/12/2024
23.0.0 1,463 12/14/2023
22.1.0 537 12/9/2023
22.0.2 1,614 12/1/2023
22.0.1 1,253 11/16/2023
22.0.0 369 11/14/2023
21.1.0 883 10/9/2023
21.0.4 845 9/15/2023
21.0.3 6,676 7/9/2023
21.0.2 681 7/6/2023
21.0.1 1,265 5/27/2023
21.0.0 4,984 4/15/2023
20.2.4 1,256 3/27/2023
20.2.3 4,704 3/17/2023
20.2.2 750 3/14/2023
20.2.1 670 3/11/2023
20.2.0 639 3/7/2023
20.1.6 1,880 2/23/2023
20.1.5 681 2/9/2023
20.1.4 1,296 1/28/2023
20.1.3 3,590 12/21/2022
20.1.2 808 12/14/2022
20.1.1 925 12/12/2022
20.1.0 802 12/4/2022
20.0.4 742 11/30/2022
20.0.3 1,814 10/28/2022
20.0.2 837 10/26/2022
20.0.1 1,134 10/21/2022
20.0.0 1,453 10/1/2022
19.4.1 984 9/10/2022
19.4.0 1,137 9/2/2022
19.3.0 1,281 8/23/2022
19.2.2 1,270 8/11/2022
19.2.1 1,248 8/6/2022
19.2.0 1,089 7/24/2022
19.1.4 7,585 5/23/2022
19.1.3 912 5/22/2022
19.1.2 890 5/18/2022
19.1.1 1,236 4/28/2022
19.1.0 3,882 4/10/2022
19.0.7 1,112 3/13/2022
19.0.6 956 3/7/2022
19.0.5 2,678 1/28/2022
19.0.4 1,495 1/23/2022
19.0.3 1,114 12/14/2021
19.0.2 809 12/11/2021
19.0.1 2,088 11/20/2021
19.0.0 993 11/11/2021
19.0.0-rc.net60.2 168 9/26/2021
19.0.0-rc.net60.1 205 9/16/2021
18.1.6 4,132 9/26/2021
18.1.5 2,476 9/7/2021
18.1.4 831 9/6/2021
18.1.3 4,775 8/19/2021
18.1.2 878 8/8/2021
18.1.1 798 8/5/2021
18.1.0 832 8/1/2021
18.0.1 863 7/30/2021
18.0.0 930 7/26/2021
17.0.8 1,692 7/7/2021
17.0.7 936 6/16/2021
17.0.6 876 6/5/2021
17.0.5 949 5/28/2021
17.0.4 5,062 5/4/2021
17.0.3 811 5/1/2021
17.0.2 934 4/22/2021
17.0.1 792 4/18/2021
17.0.0 2,114 3/26/2021
16.5.6 804 3/25/2021
16.5.5 861 3/23/2021
16.5.4 934 3/9/2021
16.5.3 1,026 2/26/2021
16.5.2 1,590 2/23/2021
16.5.1 1,495 2/21/2021
16.5.0 833 2/17/2021
16.4.5 836 2/15/2021
16.4.4 871 2/5/2021
16.4.3 857 1/27/2021
16.4.2 1,808 1/22/2021
16.4.1 910 1/21/2021
16.4.0 830 1/11/2021
16.3.3 841 1/8/2021
16.3.2 853 1/3/2021
16.3.1 888 12/31/2020
16.3.0 866 12/30/2020
16.2.1 847 12/27/2020
16.2.0 2,239 10/13/2020
16.1.5 1,062 10/4/2020
16.1.4 1,201 9/17/2020
16.1.3 1,241 9/13/2020
16.1.2 1,559 9/9/2020
16.1.1 922 9/3/2020
16.1.0 947 8/19/2020
16.0.3 918 8/15/2020
16.0.2 860 8/9/2020
16.0.1 1,002 8/8/2020
16.0.0 943 8/7/2020
15.3.0 92,923 7/23/2020
15.2.3 3,539 7/14/2020
15.2.2 2,296 5/19/2020
15.2.1 1,004 5/12/2020
15.2.0 1,389 5/9/2020
15.1.1 961 5/4/2020
15.1.0 981 4/13/2020
15.0.5 4,445 3/18/2020
15.0.4 1,004 2/28/2020
15.0.3 947 2/26/2020
15.0.2 1,052 1/20/2020
15.0.1 974 1/10/2020
15.0.0 1,005 12/17/2019
14.9.1 1,024 11/30/2019
14.9.0 955 11/29/2019
14.8.1 922 11/26/2019
14.8.0 8,649 11/20/2019
14.7.0 1,024 10/9/2019
14.6.6 961 10/8/2019
14.6.5 929 9/27/2019
14.6.4 973 9/21/2019
14.6.3 1,031 8/12/2019
14.6.2 1,155 8/3/2019
14.6.1 988 8/3/2019
14.6.0 1,265 7/26/2019
14.5.7 1,438 7/18/2019
14.5.6 1,020 7/10/2019
14.5.5 1,101 7/1/2019
14.5.4 971 6/17/2019
14.5.3 1,130 6/5/2019
14.5.2 984 5/30/2019
14.5.1 998 5/28/2019
14.5.0 3,892 5/24/2019
14.4.0 1,056 5/22/2019