tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
AbstractHttpClientFactory.cs
Go to the documentation of this file.
1using System;
2using System.Net.Http;
3
4using Microsoft.Extensions.Logging;
5
8
10{
13 {
17 readonly IHttpClientFactory httpClientFactory;
18
23
27 readonly ILogger<AbstractHttpClientFactory> logger;
28
36 IHttpClientFactory httpClientFactory,
38 ILogger<AbstractHttpClientFactory> logger)
39 {
40 this.httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory));
41 this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider));
42 this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
43 }
44
46#pragma warning disable IDE0079
47#pragma warning disable CA2000
49 {
50 logger.LogTrace("Creating client...");
51 var innerClient = httpClientFactory.CreateClient();
52 try
53 {
54 var client = new Tgstation.Server.Common.Http.HttpClient(innerClient);
55 innerClient = null;
56 try
57 {
59 return client;
60 }
61 catch
62 {
63 client.Dispose();
64 throw;
65 }
66 }
67 catch
68 {
69 innerClient?.Dispose();
70 throw;
71 }
72 }
73#pragma warning restore CA2000
74#pragma warning restore IDE0079
75 }
76}
HttpRequestHeaders DefaultRequestHeaders
The HttpRequestHeaders used on every request.
Definition HttpClient.cs:20
readonly IHttpClientFactory httpClientFactory
The real IHttpClientFactory.
readonly ILogger< AbstractHttpClientFactory > logger
The ILogger for the AbstractHttpClientFactory.
readonly IAssemblyInformationProvider assemblyInformationProvider
The IAssemblyInformationProvider for the AbstractHttpClientFactory.
AbstractHttpClientFactory(IHttpClientFactory httpClientFactory, IAssemblyInformationProvider assemblyInformationProvider, ILogger< AbstractHttpClientFactory > logger)
Initializes a new instance of the AbstractHttpClientFactory class.
IHttpClient CreateClient()
Create a IHttpClient.A new IHttpClient.
ProductInfoHeaderValue ProductInfoHeaderValue
The ProductInfoHeaderValue for the assembly.