Audit.HttpClient
27.0.2
See the version list below for details.
dotnet add package Audit.HttpClient --version 27.0.2
NuGet\Install-Package Audit.HttpClient -Version 27.0.2
<PackageReference Include="Audit.HttpClient" Version="27.0.2" />
paket add Audit.HttpClient --version 27.0.2
#r "nuget: Audit.HttpClient, 27.0.2"
// Install Audit.HttpClient as a Cake Addin #addin nuget:?package=Audit.HttpClient&version=27.0.2 // Install Audit.HttpClient as a Cake Tool #tool nuget:?package=Audit.HttpClient&version=27.0.2
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
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 ofHttpClient
:
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 newHttpClient
with a customAuditHttpClientHandler
as its message handler.
- If you use ASP .NET dependency injection /
HttpClientFactory
, you can add the message handler with the extension methodAddAuditHandler()
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 forAddHttpMessageHandler(() => 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 | Versions 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. |
-
.NETFramework 4.6.2
- Audit.NET (>= 27.0.2)
- Microsoft.Extensions.Http (>= 8.0.0)
- System.Net.Http (>= 4.3.4)
-
.NETStandard 2.0
- Audit.NET (>= 27.0.2)
- Microsoft.Extensions.Http (>= 8.0.0)
- System.Net.Http (>= 4.3.4)
-
.NETStandard 2.1
- Audit.NET (>= 27.0.2)
- Microsoft.Extensions.Http (>= 8.0.0)
- System.Net.Http (>= 4.3.4)
-
net6.0
- Audit.NET (>= 27.0.2)
- Microsoft.Extensions.Http (>= 8.0.0)
- System.Net.Http (>= 4.3.4)
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 | 122 | 12/11/2024 |
27.3.1 | 77 | 12/10/2024 |
27.3.0 | 92 | 12/8/2024 |
27.2.0 | 923 | 11/23/2024 |
27.1.1 | 1,236 | 10/28/2024 |
27.1.0 | 133 | 10/24/2024 |
27.0.3 | 1,348 | 9/25/2024 |
27.0.2 | 619 | 9/19/2024 |
27.0.1 | 413 | 9/4/2024 |
27.0.0 | 130 | 9/3/2024 |
26.0.1 | 1,003 | 8/22/2024 |
26.0.0 | 384 | 7/19/2024 |
25.0.7 | 14,727 | 7/4/2024 |
25.0.6 | 2,338 | 6/24/2024 |
25.0.5 | 526 | 6/18/2024 |
25.0.4 | 3,494 | 3/24/2024 |
25.0.3 | 944 | 3/13/2024 |
25.0.2 | 183 | 3/12/2024 |
25.0.1 | 2,135 | 2/28/2024 |
25.0.0 | 295 | 2/16/2024 |
24.0.1 | 922 | 2/12/2024 |
24.0.0 | 258 | 2/12/2024 |
23.0.0 | 2,925 | 12/14/2023 |
22.1.0 | 842 | 12/9/2023 |
22.0.2 | 6,283 | 12/1/2023 |
22.0.1 | 1,629 | 11/16/2023 |
22.0.0 | 479 | 11/14/2023 |
21.1.0 | 1,435 | 10/9/2023 |
21.0.4 | 1,034 | 9/15/2023 |
21.0.3 | 11,227 | 7/9/2023 |
21.0.2 | 747 | 7/6/2023 |
21.0.1 | 1,529 | 5/27/2023 |
21.0.0 | 10,079 | 4/15/2023 |
20.2.4 | 1,427 | 3/27/2023 |
20.2.3 | 9,674 | 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,398 | 1/28/2023 |
20.1.3 | 3,946 | 12/21/2022 |
20.1.2 | 940 | 12/14/2022 |
20.1.1 | 1,014 | 12/12/2022 |
20.1.0 | 874 | 12/4/2022 |
20.0.4 | 804 | 11/30/2022 |
20.0.3 | 1,902 | 10/28/2022 |
20.0.2 | 898 | 10/26/2022 |
20.0.1 | 1,207 | 10/21/2022 |
20.0.0 | 1,543 | 10/1/2022 |
19.4.1 | 1,052 | 9/10/2022 |
19.4.0 | 1,294 | 9/2/2022 |
19.3.0 | 1,341 | 8/23/2022 |
19.2.2 | 1,352 | 8/11/2022 |
19.2.1 | 1,860 | 8/6/2022 |
19.2.0 | 1,155 | 7/24/2022 |
19.1.4 | 7,807 | 5/23/2022 |
19.1.3 | 984 | 5/22/2022 |
19.1.2 | 963 | 5/18/2022 |
19.1.1 | 1,311 | 4/28/2022 |
19.1.0 | 3,946 | 4/10/2022 |
19.0.7 | 1,176 | 3/13/2022 |
19.0.6 | 1,017 | 3/7/2022 |
19.0.5 | 2,789 | 1/28/2022 |
19.0.4 | 1,565 | 1/23/2022 |
19.0.3 | 1,199 | 12/14/2021 |
19.0.2 | 860 | 12/11/2021 |
19.0.1 | 2,162 | 11/20/2021 |
19.0.0 | 1,101 | 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,318 | 9/26/2021 |
18.1.5 | 2,544 | 9/7/2021 |
18.1.4 | 890 | 9/6/2021 |
18.1.3 | 4,905 | 8/19/2021 |
18.1.2 | 940 | 8/8/2021 |
18.1.1 | 862 | 8/5/2021 |
18.1.0 | 897 | 8/1/2021 |
18.0.1 | 923 | 7/30/2021 |
18.0.0 | 1,002 | 7/26/2021 |
17.0.8 | 1,804 | 7/7/2021 |
17.0.7 | 1,011 | 6/16/2021 |
17.0.6 | 920 | 6/5/2021 |
17.0.5 | 1,100 | 5/28/2021 |
17.0.4 | 5,771 | 5/4/2021 |
17.0.3 | 880 | 5/1/2021 |
17.0.2 | 1,014 | 4/22/2021 |
17.0.1 | 855 | 4/18/2021 |
17.0.0 | 2,191 | 3/26/2021 |
16.5.6 | 854 | 3/25/2021 |
16.5.5 | 938 | 3/23/2021 |
16.5.4 | 985 | 3/9/2021 |
16.5.3 | 1,108 | 2/26/2021 |
16.5.2 | 1,710 | 2/23/2021 |
16.5.1 | 1,602 | 2/21/2021 |
16.5.0 | 921 | 2/17/2021 |
16.4.5 | 877 | 2/15/2021 |
16.4.4 | 943 | 2/5/2021 |
16.4.3 | 931 | 1/27/2021 |
16.4.2 | 1,882 | 1/22/2021 |
16.4.1 | 968 | 1/21/2021 |
16.4.0 | 893 | 1/11/2021 |
16.3.3 | 914 | 1/8/2021 |
16.3.2 | 917 | 1/3/2021 |
16.3.1 | 960 | 12/31/2020 |
16.3.0 | 939 | 12/30/2020 |
16.2.1 | 926 | 12/27/2020 |
16.2.0 | 2,371 | 10/13/2020 |
16.1.5 | 1,127 | 10/4/2020 |
16.1.4 | 1,290 | 9/17/2020 |
16.1.3 | 1,325 | 9/13/2020 |
16.1.2 | 1,686 | 9/9/2020 |
16.1.1 | 1,002 | 9/3/2020 |
16.1.0 | 1,037 | 8/19/2020 |
16.0.3 | 970 | 8/15/2020 |
16.0.2 | 940 | 8/9/2020 |
16.0.1 | 1,081 | 8/8/2020 |
16.0.0 | 1,006 | 8/7/2020 |
15.3.0 | 114,131 | 7/23/2020 |
15.2.3 | 3,620 | 7/14/2020 |
15.2.2 | 3,060 | 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,509 | 3/18/2020 |
15.0.4 | 1,070 | 2/28/2020 |
15.0.3 | 992 | 2/26/2020 |
15.0.2 | 1,121 | 1/20/2020 |
15.0.1 | 1,022 | 1/10/2020 |
15.0.0 | 1,058 | 12/17/2019 |
14.9.1 | 1,115 | 11/30/2019 |
14.9.0 | 1,000 | 11/29/2019 |
14.8.1 | 994 | 11/26/2019 |
14.8.0 | 8,713 | 11/20/2019 |
14.7.0 | 1,084 | 10/9/2019 |
14.6.6 | 1,023 | 10/8/2019 |
14.6.5 | 1,017 | 9/27/2019 |
14.6.4 | 1,030 | 9/21/2019 |
14.6.3 | 1,084 | 8/12/2019 |
14.6.2 | 1,227 | 8/3/2019 |
14.6.1 | 1,068 | 8/3/2019 |
14.6.0 | 1,317 | 7/26/2019 |
14.5.7 | 1,704 | 7/18/2019 |
14.5.6 | 1,071 | 7/10/2019 |
14.5.5 | 1,450 | 7/1/2019 |
14.5.4 | 1,045 | 6/17/2019 |
14.5.3 | 1,214 | 6/5/2019 |
14.5.2 | 1,041 | 5/30/2019 |
14.5.1 | 1,072 | 5/28/2019 |
14.5.0 | 3,962 | 5/24/2019 |
14.4.0 | 1,127 | 5/22/2019 |