-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTTP.cs
More file actions
67 lines (61 loc) · 1.9 KB
/
HTTP.cs
File metadata and controls
67 lines (61 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using AuthSharp.SDK.Exceptions;
using RestSharp;
namespace AuthSharp.SDK
{
/// <summary>
/// Internal HTTP client wrapper for managing REST API communication.
/// </summary>
internal class HTTP : IDisposable
{
/// <summary>
/// The default host URL for the AuthSharp server.
/// </summary>
public const string HOST = "https://api.authsharp.net";
/// <summary>
/// Gets or sets the REST client instance used for HTTP requests.
/// </summary>
public RestClient Client { get; set; } = new RestClient(HOST, options =>
{
options.Timeout = TimeSpan.FromSeconds(30);
options.UserAgent = "AuthSharp.SDK/1.0";
});
private bool _disposed = false;
/// <summary>
/// Adds a default header to all HTTP requests.
/// </summary>
/// <param name="Name">The header name.</param>
/// <param name="Value">The header value.</param>
public void AddDefaultHeader(string Name, string Value)
{
Client.AddDefaultHeader(Name, Value);
}
/// <summary>
/// Disposes of the HTTP client and releases associated resources.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Protected implementation of Dispose pattern.
/// </summary>
/// <param name="disposing">Whether to dispose managed resources.</param>
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
Client?.Dispose();
}
_disposed = true;
}
}
}
}