Audit.HttpClient 27.3.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Audit.HttpClient --version 27.3.1                
NuGet\Install-Package Audit.HttpClient -Version 27.3.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="Audit.HttpClient" Version="27.3.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Audit.HttpClient --version 27.3.1                
#r "nuget: Audit.HttpClient, 27.3.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 Audit.HttpClient as a Cake Addin
#addin nuget:?package=Audit.HttpClient&version=27.3.1

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

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.
  • IncludeOptions: Specifies which HTTP Request Options should be included in the audit output. Useful to add contextual information to the HTTP Audit Event. By default, the options are not included.
  • 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 globally configured 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
27.3.2 112 12/11/2024
27.3.1 76 12/10/2024
27.3.0 91 12/8/2024
27.2.0 891 11/23/2024
27.1.1 1,217 10/28/2024
27.1.0 133 10/24/2024
27.0.3 1,348 9/25/2024
27.0.2 612 9/19/2024
27.0.1 411 9/4/2024
27.0.0 130 9/3/2024
26.0.1 1,003 8/22/2024
26.0.0 383 7/19/2024
25.0.7 14,710 7/4/2024
25.0.6 2,338 6/24/2024
25.0.5 526 6/18/2024
25.0.4 3,476 3/24/2024
25.0.3 905 3/13/2024
25.0.2 183 3/12/2024
25.0.1 2,065 2/28/2024
25.0.0 295 2/16/2024
24.0.1 901 2/12/2024
24.0.0 258 2/12/2024
23.0.0 2,895 12/14/2023
22.1.0 842 12/9/2023
22.0.2 6,213 12/1/2023
22.0.1 1,629 11/16/2023
22.0.0 477 11/14/2023
21.1.0 1,413 10/9/2023
21.0.4 1,026 9/15/2023
21.0.3 11,129 7/9/2023
21.0.2 747 7/6/2023
21.0.1 1,527 5/27/2023
21.0.0 9,981 4/15/2023
20.2.4 1,424 3/27/2023
20.2.3 9,621 3/17/2023
20.2.2 809 3/14/2023
20.2.1 736 3/11/2023
20.2.0 707 3/7/2023
20.1.6 2,479 2/23/2023
20.1.5 751 2/9/2023
20.1.4 2,385 1/28/2023
20.1.3 3,942 12/21/2022
20.1.2 940 12/14/2022
20.1.1 1,014 12/12/2022
20.1.0 872 12/4/2022
20.0.4 802 11/30/2022
20.0.3 1,900 10/28/2022
20.0.2 896 10/26/2022
20.0.1 1,205 10/21/2022
20.0.0 1,541 10/1/2022
19.4.1 1,050 9/10/2022
19.4.0 1,289 9/2/2022
19.3.0 1,339 8/23/2022
19.2.2 1,350 8/11/2022
19.2.1 1,840 8/6/2022
19.2.0 1,153 7/24/2022
19.1.4 7,805 5/23/2022
19.1.3 982 5/22/2022
19.1.2 961 5/18/2022
19.1.1 1,309 4/28/2022
19.1.0 3,944 4/10/2022
19.0.7 1,174 3/13/2022
19.0.6 1,015 3/7/2022
19.0.5 2,787 1/28/2022
19.0.4 1,563 1/23/2022
19.0.3 1,197 12/14/2021
19.0.2 858 12/11/2021
19.0.1 2,158 11/20/2021
19.0.0 1,099 11/11/2021
19.0.0-rc.net60.2 182 9/26/2021
19.0.0-rc.net60.1 222 9/16/2021
18.1.6 4,316 9/26/2021
18.1.5 2,542 9/7/2021
18.1.4 888 9/6/2021
18.1.3 4,903 8/19/2021
18.1.2 938 8/8/2021
18.1.1 859 8/5/2021
18.1.0 893 8/1/2021
18.0.1 921 7/30/2021
18.0.0 1,000 7/26/2021
17.0.8 1,802 7/7/2021
17.0.7 1,009 6/16/2021
17.0.6 918 6/5/2021
17.0.5 1,098 5/28/2021
17.0.4 5,767 5/4/2021
17.0.3 876 5/1/2021
17.0.2 1,012 4/22/2021
17.0.1 853 4/18/2021
17.0.0 2,189 3/26/2021
16.5.6 852 3/25/2021
16.5.5 936 3/23/2021
16.5.4 984 3/9/2021
16.5.3 1,106 2/26/2021
16.5.2 1,708 2/23/2021
16.5.1 1,600 2/21/2021
16.5.0 919 2/17/2021
16.4.5 875 2/15/2021
16.4.4 941 2/5/2021
16.4.3 930 1/27/2021
16.4.2 1,880 1/22/2021
16.4.1 966 1/21/2021
16.4.0 891 1/11/2021
16.3.3 912 1/8/2021
16.3.2 915 1/3/2021
16.3.1 958 12/31/2020
16.3.0 937 12/30/2020
16.2.1 924 12/27/2020
16.2.0 2,367 10/13/2020
16.1.5 1,125 10/4/2020
16.1.4 1,288 9/17/2020
16.1.3 1,323 9/13/2020
16.1.2 1,684 9/9/2020
16.1.1 1,000 9/3/2020
16.1.0 1,033 8/19/2020
16.0.3 968 8/15/2020
16.0.2 938 8/9/2020
16.0.1 1,079 8/8/2020
16.0.0 1,004 8/7/2020
15.3.0 113,858 7/23/2020
15.2.3 3,620 7/14/2020
15.2.2 3,012 5/19/2020
15.2.1 1,086 5/12/2020
15.2.0 1,456 5/9/2020
15.1.1 1,043 5/4/2020
15.1.0 1,048 4/13/2020
15.0.5 4,508 3/18/2020
15.0.4 1,069 2/28/2020
15.0.3 991 2/26/2020
15.0.2 1,120 1/20/2020
15.0.1 1,021 1/10/2020
15.0.0 1,057 12/17/2019
14.9.1 1,114 11/30/2019
14.9.0 999 11/29/2019
14.8.1 993 11/26/2019
14.8.0 8,712 11/20/2019
14.7.0 1,082 10/9/2019
14.6.6 1,022 10/8/2019
14.6.5 1,016 9/27/2019
14.6.4 1,028 9/21/2019
14.6.3 1,082 8/12/2019
14.6.2 1,226 8/3/2019
14.6.1 1,066 8/3/2019
14.6.0 1,316 7/26/2019
14.5.7 1,688 7/18/2019
14.5.6 1,070 7/10/2019
14.5.5 1,449 7/1/2019
14.5.4 1,044 6/17/2019
14.5.3 1,213 6/5/2019
14.5.2 1,040 5/30/2019
14.5.1 1,071 5/28/2019
14.5.0 3,961 5/24/2019
14.4.0 1,126 5/22/2019