-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from novuhq/83-add-user-agent-header
feat: add version to user-agent header #83
- Loading branch information
Showing
3 changed files
with
76 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,38 @@ | ||
using System.Reflection; | ||
|
||
namespace Novu.Domain; | ||
|
||
public static class NovuConstants | ||
{ | ||
public static readonly int MaxPageSize = 100; | ||
|
||
/// <summary> | ||
/// Returns the properly formatted User-Agent header string for the `novu-dotnet` package, | ||
/// including the version retrieved from the NuGet package version. | ||
/// </summary> | ||
/// <returns> | ||
/// A string in the format `novu-dotnet/{version}`, where {version} is the version of the NuGet package. | ||
/// If no version is found, it defaults to `novu-dotnet/0.0.0`. | ||
/// </returns> | ||
/// <remarks> | ||
/// The version is retrieved from the assembly's <see cref="AssemblyInformationalVersionAttribute" />. | ||
/// If the version is not specified in the assembly, it falls back to `0.0.0` as the default version. | ||
/// This ensures compliance with the HTTP specification for the User-Agent header format, as outlined in RFC 7231. | ||
/// </remarks> | ||
/// <example> | ||
/// Example usage: | ||
/// <code> | ||
/// string userAgent = NovuConstants.UserAgent(); | ||
/// Console.WriteLine(userAgent); // Outputs: novu-dotnet/1.2.3 (if version is 1.2.3) | ||
/// </code> | ||
/// </example> | ||
public static string UserAgent() | ||
{ | ||
// Add a User-Agent header if enabled | ||
var version = Assembly | ||
.GetExecutingAssembly() | ||
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()? | ||
.InformationalVersion ?? "0.0.0"; | ||
return $"novu-dotnet/{version}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters