Skip to content

Commit a91ae00

Browse files
author
Alex
committed
Add flag to enable/disable the User-Agent suffix
1 parent 78d8efb commit a91ae00

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

RedditSharp/WebAgent.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class WebAgent : IWebAgent
1919
/// <summary>
2020
/// Additional values to append to the default RedditSharp user agent.
2121
/// </summary>
22-
public static string DefaultUserAgent { get; set; }
22+
public static string DefaultUserAgent { get; set; } = "RedditSharp";
2323

2424
/// <summary>
2525
/// web protocol "http", "https"
@@ -50,6 +50,11 @@ public class WebAgent : IWebAgent
5050
/// </summary>
5151
public string UserAgent { get; set; }
5252

53+
/// <summary>
54+
/// Append the library to the end of the User-Agent string. Default is true.
55+
/// </summary>
56+
public bool AppendLibraryToUA { get; set; } = true;
57+
5358
private static readonly bool IsMono = Type.GetType("Mono.Runtime") != null;
5459
private static bool IsOAuth => RootDomain == "oauth.reddit.com";
5560

@@ -190,7 +195,8 @@ protected virtual HttpRequestMessage CreateRequest(Uri uri, string method)
190195

191196
request.Method = new HttpMethod(method);
192197
//request.Headers.UserAgent.ParseAdd(UserAgent);
193-
request.Headers.TryAddWithoutValidation("User-Agent", $"{UserAgent} - with RedditSharp by meepster23");
198+
var userAgentString = AppendLibraryToUA ? $"{UserAgent} - with RedditSharp by meepster23" : UserAgent;
199+
request.Headers.TryAddWithoutValidation("User-Agent", userAgentString);
194200
return request;
195201
}
196202

0 commit comments

Comments
 (0)