diff --git a/arangodb-net-standard/CustomHttpHeaders.cs b/arangodb-net-standard/CustomHttpHeaders.cs index a2935323..ada9b7f1 100644 --- a/arangodb-net-standard/CustomHttpHeaders.cs +++ b/arangodb-net-standard/CustomHttpHeaders.cs @@ -14,5 +14,9 @@ public static class CustomHttpHeaders /// Introduced in ArangoDB 3.10. /// public const string ReadFromFollowersHeader = "x-arango-allow-dirty-read"; + /// + /// The header string used for Driver Info Header + /// + public const string DriverInfoHeader = "x-arango-driver"; } } diff --git a/arangodb-net-standard/DriverConstants.cs b/arangodb-net-standard/DriverConstants.cs new file mode 100644 index 00000000..b66e6629 --- /dev/null +++ b/arangodb-net-standard/DriverConstants.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ArangoDBNetStandard +{ + /// + /// Global constants to be used throughout the driver + /// + public static class DriverConstants + { + /// + /// Name of the driver + /// + public const string DriverName = "arangodb-net-standard"; + } +} diff --git a/arangodb-net-standard/Transport/Http/HttpApiTransport.cs b/arangodb-net-standard/Transport/Http/HttpApiTransport.cs index b1f52392..94b2b71e 100644 --- a/arangodb-net-standard/Transport/Http/HttpApiTransport.cs +++ b/arangodb-net-standard/Transport/Http/HttpApiTransport.cs @@ -3,6 +3,7 @@ using System.Net; using System.Net.Http; using System.Net.Http.Headers; +using System.Reflection; using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; using System.Text; @@ -31,6 +32,11 @@ public class HttpApiTransport : IApiClientTransport [HttpContentType.VPack] = "application/x-velocypack" }; + /// + /// Flags containing specific driver information. + /// + public IEnumerable DriverFlags { get; set; } + /// /// Create from an existing instance. /// @@ -48,7 +54,8 @@ public HttpApiTransport(HttpClient client, HttpContentType contentType) /// /// Object containing a dictionary of Header keys and values. /// The header to update. - private static void ApplyHeaders(WebHeaderCollection webHeaderCollection, HttpHeaders headers) + /// Driver flags that are passed to the server. + private static void ApplyHeaders(WebHeaderCollection webHeaderCollection, HttpHeaders headers, IEnumerable driverFlags = null) { if (webHeaderCollection != null) { @@ -57,6 +64,14 @@ private static void ApplyHeaders(WebHeaderCollection webHeaderCollection, HttpHe headers.Add(key, webHeaderCollection[key]); } } + //build and add driver info header + string flags = string.Empty; + if (driverFlags != null) + { + flags = string.Join(";", driverFlags); + } + var assemblyInfo = Assembly.GetCallingAssembly().GetName(); + headers.Add(CustomHttpHeaders.DriverInfoHeader, $"{DriverConstants.DriverName}/{assemblyInfo.Version} ({flags})"); } /// @@ -284,7 +299,7 @@ public async Task DeleteAsync( CancellationToken token = default) { var request = new HttpRequestMessage(HttpMethod.Delete, requestUri); - ApplyHeaders(webHeaderCollection, request.Headers); + ApplyHeaders(webHeaderCollection, request.Headers,DriverFlags); var response = await _client.SendAsync(request, token).ConfigureAwait(false); return new HttpApiClientResponse(response); } @@ -309,7 +324,7 @@ public async Task DeleteAsync( }; request.Content.Headers.ContentType = new MediaTypeHeaderValue(_contentTypeMap[_contentType]); - ApplyHeaders(webHeaderCollection, request.Content.Headers); + ApplyHeaders(webHeaderCollection, request.Content.Headers, DriverFlags); var response = await _client.SendAsync(request, token).ConfigureAwait(false); return new HttpApiClientResponse(response); } @@ -330,7 +345,7 @@ public async Task PostAsync( { var httpContent = new ByteArrayContent(content); httpContent.Headers.ContentType = new MediaTypeHeaderValue(_contentTypeMap[_contentType]); - ApplyHeaders(webHeaderCollection, httpContent.Headers); + ApplyHeaders(webHeaderCollection, httpContent.Headers, DriverFlags); var response = await _client.PostAsync(requestUri, httpContent, token).ConfigureAwait(false); return new HttpApiClientResponse(response); } @@ -351,7 +366,7 @@ public async Task PutAsync( { var httpContent = new ByteArrayContent(content); httpContent.Headers.ContentType = new MediaTypeHeaderValue(_contentTypeMap[_contentType]); - ApplyHeaders(webHeaderCollection, httpContent.Headers); + ApplyHeaders(webHeaderCollection, httpContent.Headers, DriverFlags); var response = await _client.PutAsync(requestUri, httpContent, token).ConfigureAwait(false); return new HttpApiClientResponse(response); } @@ -369,7 +384,7 @@ public async Task GetAsync( CancellationToken token = default) { var request = new HttpRequestMessage(HttpMethod.Get, requestUri); - ApplyHeaders(webHeaderCollection, request.Headers); + ApplyHeaders(webHeaderCollection, request.Headers, DriverFlags); var response = await _client.SendAsync(request, token).ConfigureAwait(false); return new HttpApiClientResponse(response); } @@ -395,7 +410,7 @@ public async Task PatchAsync( }; request.Content.Headers.ContentType = new MediaTypeHeaderValue(_contentTypeMap[_contentType]); - ApplyHeaders(webHeaderCollection, request.Content.Headers); + ApplyHeaders(webHeaderCollection, request.Content.Headers, DriverFlags); var response = await _client.SendAsync(request, token).ConfigureAwait(false); return new HttpApiClientResponse(response); } @@ -413,7 +428,7 @@ public async Task HeadAsync( CancellationToken token = default) { var request = new HttpRequestMessage(HttpMethod.Head, requestUri); - ApplyHeaders(webHeaderCollection, request.Headers); + ApplyHeaders(webHeaderCollection, request.Headers, DriverFlags); var response = await _client.SendAsync(request, token); return new HttpApiClientResponse(response); } diff --git a/arangodb-net-standard/Transport/IApiClientTransport.cs b/arangodb-net-standard/Transport/IApiClientTransport.cs index 30aec861..fb395a2c 100644 --- a/arangodb-net-standard/Transport/IApiClientTransport.cs +++ b/arangodb-net-standard/Transport/IApiClientTransport.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Net; using System.Threading; using System.Threading.Tasks; @@ -10,6 +11,11 @@ namespace ArangoDBNetStandard.Transport /// public interface IApiClientTransport : IDisposable { + /// + /// Flags containing specific driver information. + /// + IEnumerable DriverFlags { get; set; } + /// /// Send a POST request. ///