Audit.HttpClient
25.0.6
See the version list below for details.
dotnet add package Audit.HttpClient --version 25.0.6
NuGet\Install-Package Audit.HttpClient -Version 25.0.6
<PackageReference Include="Audit.HttpClient" Version="25.0.6" />
paket add Audit.HttpClient --version 25.0.6
#r "nuget: Audit.HttpClient, 25.0.6"
// Install Audit.HttpClient as a Cake Addin #addin nuget:?package=Audit.HttpClient&version=25.0.6 // Install Audit.HttpClient as a Cake Tool #tool nuget:?package=Audit.HttpClient&version=25.0.6
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.
- 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 | 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 (>= 25.0.6)
- Microsoft.Extensions.Http (>= 8.0.0)
- System.Net.Http (>= 4.3.4)
-
.NETStandard 2.0
- Audit.NET (>= 25.0.6)
- Microsoft.Extensions.Http (>= 8.0.0)
- System.Net.Http (>= 4.3.4)
-
.NETStandard 2.1
- Audit.NET (>= 25.0.6)
- Microsoft.Extensions.Http (>= 8.0.0)
- System.Net.Http (>= 4.3.4)
-
net6.0
- Audit.NET (>= 25.0.6)
- 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.1.1 | 668 | 10/28/2024 |
27.1.0 | 119 | 10/24/2024 |
27.0.3 | 953 | 9/25/2024 |
27.0.2 | 566 | 9/19/2024 |
27.0.1 | 387 | 9/4/2024 |
27.0.0 | 120 | 9/3/2024 |
26.0.1 | 953 | 8/22/2024 |
26.0.0 | 371 | 7/19/2024 |
25.0.7 | 12,467 | 7/4/2024 |
25.0.6 | 2,323 | 6/24/2024 |
25.0.5 | 513 | 6/18/2024 |
25.0.4 | 3,328 | 3/24/2024 |
25.0.3 | 806 | 3/13/2024 |
25.0.2 | 178 | 3/12/2024 |
25.0.1 | 1,794 | 2/28/2024 |
25.0.0 | 290 | 2/16/2024 |
24.0.1 | 843 | 2/12/2024 |
24.0.0 | 249 | 2/12/2024 |
23.0.0 | 2,692 | 12/14/2023 |
22.1.0 | 805 | 12/9/2023 |
22.0.2 | 6,043 | 12/1/2023 |
22.0.1 | 1,602 | 11/16/2023 |
22.0.0 | 460 | 11/14/2023 |
21.1.0 | 1,367 | 10/9/2023 |
21.0.4 | 983 | 9/15/2023 |
21.0.3 | 10,670 | 7/9/2023 |
21.0.2 | 742 | 7/6/2023 |
21.0.1 | 1,513 | 5/27/2023 |
21.0.0 | 9,277 | 4/15/2023 |
20.2.4 | 1,403 | 3/27/2023 |
20.2.3 | 9,064 | 3/17/2023 |
20.2.2 | 804 | 3/14/2023 |
20.2.1 | 732 | 3/11/2023 |
20.2.0 | 702 | 3/7/2023 |
20.1.6 | 2,472 | 2/23/2023 |
20.1.5 | 746 | 2/9/2023 |
20.1.4 | 2,086 | 1/28/2023 |
20.1.3 | 3,912 | 12/21/2022 |
20.1.2 | 927 | 12/14/2022 |
20.1.1 | 1,009 | 12/12/2022 |
20.1.0 | 867 | 12/4/2022 |
20.0.4 | 797 | 11/30/2022 |
20.0.3 | 1,888 | 10/28/2022 |
20.0.2 | 891 | 10/26/2022 |
20.0.1 | 1,198 | 10/21/2022 |
20.0.0 | 1,536 | 10/1/2022 |
19.4.1 | 1,044 | 9/10/2022 |
19.4.0 | 1,284 | 9/2/2022 |
19.3.0 | 1,334 | 8/23/2022 |
19.2.2 | 1,345 | 8/11/2022 |
19.2.1 | 1,797 | 8/6/2022 |
19.2.0 | 1,148 | 7/24/2022 |
19.1.4 | 7,766 | 5/23/2022 |
19.1.3 | 977 | 5/22/2022 |
19.1.2 | 956 | 5/18/2022 |
19.1.1 | 1,304 | 4/28/2022 |
19.1.0 | 3,939 | 4/10/2022 |
19.0.7 | 1,169 | 3/13/2022 |
19.0.6 | 1,010 | 3/7/2022 |
19.0.5 | 2,780 | 1/28/2022 |
19.0.4 | 1,558 | 1/23/2022 |
19.0.3 | 1,190 | 12/14/2021 |
19.0.2 | 853 | 12/11/2021 |
19.0.1 | 2,153 | 11/20/2021 |
19.0.0 | 1,094 | 11/11/2021 |
19.0.0-rc.net60.2 | 179 | 9/26/2021 |
19.0.0-rc.net60.1 | 215 | 9/16/2021 |
18.1.6 | 4,288 | 9/26/2021 |
18.1.5 | 2,537 | 9/7/2021 |
18.1.4 | 883 | 9/6/2021 |
18.1.3 | 4,890 | 8/19/2021 |
18.1.2 | 933 | 8/8/2021 |
18.1.1 | 854 | 8/5/2021 |
18.1.0 | 888 | 8/1/2021 |
18.0.1 | 916 | 7/30/2021 |
18.0.0 | 990 | 7/26/2021 |
17.0.8 | 1,793 | 7/7/2021 |
17.0.7 | 1,004 | 6/16/2021 |
17.0.6 | 911 | 6/5/2021 |
17.0.5 | 1,056 | 5/28/2021 |
17.0.4 | 5,725 | 5/4/2021 |
17.0.3 | 871 | 5/1/2021 |
17.0.2 | 1,007 | 4/22/2021 |
17.0.1 | 848 | 4/18/2021 |
17.0.0 | 2,184 | 3/26/2021 |
16.5.6 | 847 | 3/25/2021 |
16.5.5 | 931 | 3/23/2021 |
16.5.4 | 977 | 3/9/2021 |
16.5.3 | 1,101 | 2/26/2021 |
16.5.2 | 1,697 | 2/23/2021 |
16.5.1 | 1,581 | 2/21/2021 |
16.5.0 | 904 | 2/17/2021 |
16.4.5 | 870 | 2/15/2021 |
16.4.4 | 936 | 2/5/2021 |
16.4.3 | 925 | 1/27/2021 |
16.4.2 | 1,873 | 1/22/2021 |
16.4.1 | 961 | 1/21/2021 |
16.4.0 | 882 | 1/11/2021 |
16.3.3 | 903 | 1/8/2021 |
16.3.2 | 910 | 1/3/2021 |
16.3.1 | 952 | 12/31/2020 |
16.3.0 | 932 | 12/30/2020 |
16.2.1 | 919 | 12/27/2020 |
16.2.0 | 2,359 | 10/13/2020 |
16.1.5 | 1,120 | 10/4/2020 |
16.1.4 | 1,283 | 9/17/2020 |
16.1.3 | 1,318 | 9/13/2020 |
16.1.2 | 1,679 | 9/9/2020 |
16.1.1 | 995 | 9/3/2020 |
16.1.0 | 1,028 | 8/19/2020 |
16.0.3 | 963 | 8/15/2020 |
16.0.2 | 933 | 8/9/2020 |
16.0.1 | 1,074 | 8/8/2020 |
16.0.0 | 999 | 8/7/2020 |
15.3.0 | 111,564 | 7/23/2020 |
15.2.3 | 3,613 | 7/14/2020 |
15.2.2 | 2,807 | 5/19/2020 |
15.2.1 | 1,079 | 5/12/2020 |
15.2.0 | 1,448 | 5/9/2020 |
15.1.1 | 1,036 | 5/4/2020 |
15.1.0 | 1,041 | 4/13/2020 |
15.0.5 | 4,501 | 3/18/2020 |
15.0.4 | 1,062 | 2/28/2020 |
15.0.3 | 984 | 2/26/2020 |
15.0.2 | 1,113 | 1/20/2020 |
15.0.1 | 1,014 | 1/10/2020 |
15.0.0 | 1,050 | 12/17/2019 |
14.9.1 | 1,101 | 11/30/2019 |
14.9.0 | 992 | 11/29/2019 |
14.8.1 | 986 | 11/26/2019 |
14.8.0 | 8,704 | 11/20/2019 |
14.7.0 | 1,073 | 10/9/2019 |
14.6.6 | 1,015 | 10/8/2019 |
14.6.5 | 1,009 | 9/27/2019 |
14.6.4 | 1,021 | 9/21/2019 |
14.6.3 | 1,075 | 8/12/2019 |
14.6.2 | 1,219 | 8/3/2019 |
14.6.1 | 1,059 | 8/3/2019 |
14.6.0 | 1,310 | 7/26/2019 |
14.5.7 | 1,618 | 7/18/2019 |
14.5.6 | 1,063 | 7/10/2019 |
14.5.5 | 1,349 | 7/1/2019 |
14.5.4 | 1,037 | 6/17/2019 |
14.5.3 | 1,206 | 6/5/2019 |
14.5.2 | 1,033 | 5/30/2019 |
14.5.1 | 1,064 | 5/28/2019 |
14.5.0 | 3,954 | 5/24/2019 |
14.4.0 | 1,117 | 5/22/2019 |