Skip to content

Commit 35bc17e

Browse files
jstasiakbarijaona
authored andcommitted
Configure the user agent during the initial subscription
I saw in the HTTP logs that when creating a new subscription the reader presented itself as Vienna/8414 CFNetwork/3826.400.120 Darwin/24.3.0 while later, during refreshing the feed/subscription it sent the user agent set to Vienna/8414 (Macintosh; Intel macOS 15_3_0) and I figured I'd make that consistent.
1 parent c8f8f8c commit 35bc17e

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

Vienna/Sources/Fetching/RefreshManager.m

+2-8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#import "Vienna-Swift.h"
3939
#import "XMLFeed.h"
4040
#import "XMLFeedParser.h"
41+
#import "HelperFunctions.h"
4142

4243
typedef NS_ENUM (NSInteger, Redirect301Status) {
4344
HTTP301Unknown = 0,
@@ -96,16 +97,9 @@ -(instancetype)init
9697
networkQueue = [[NSOperationQueue alloc] init];
9798
networkQueue.name = @"VNAHTTPSession queue";
9899
networkQueue.maxConcurrentOperationCount = [[Preferences standardPreferences] integerForKey:MAPref_ConcurrentDownloads];
99-
NSString * osVersion;
100-
NSOperatingSystemVersion version = [NSProcessInfo processInfo].operatingSystemVersion;
101-
osVersion = [NSString stringWithFormat:@"%ld_%ld_%ld", version.majorVersion, version.minorVersion, version.patchVersion];
102-
Preferences * prefs = [Preferences standardPreferences];
103-
NSString *name = prefs.userAgentName;
104-
105-
NSString * userAgent = [NSString stringWithFormat:MA_DefaultUserAgentString, name, [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"], osVersion];
106100
NSURLSessionConfiguration * config = [NSURLSessionConfiguration defaultSessionConfiguration];
107101
config.timeoutIntervalForResource = 300;
108-
config.HTTPAdditionalHeaders = @{@"User-Agent": userAgent};
102+
config.HTTPAdditionalHeaders = @{@"User-Agent": userAgent()};
109103
config.HTTPMaximumConnectionsPerHost = 6;
110104
config.HTTPShouldUsePipelining = YES;
111105
_urlSession = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:[NSOperationQueue mainQueue]];

Vienna/Sources/Shared/HelperFunctions.h

+1
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ NSString * _Nullable getDefaultBrowser(void);
5151
NSURL * _Nullable cleanedUpUrlFromString(NSString * _Nullable urlString);
5252
NSURL * _Nullable urlFromUserString(NSString *urlString);
5353
BOOL hasOSScriptsMenu(void);
54+
NSString * userAgent(void);
5455

5556
NS_ASSUME_NONNULL_END

Vienna/Sources/Shared/HelperFunctions.m

+13
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
//
1919

2020
#import "HelperFunctions.h"
21+
#import "Constants.h"
22+
#import "Preferences.h"
2123
@import WebKit;
2224

2325
// Determines whether the system-wide script menu is present. This is usually
@@ -241,3 +243,14 @@ void runOKAlertSheet(NSString * titleString, NSString * bodyText, ...)
241243

242244
va_end(arguments);
243245
}
246+
247+
/* Returns a fully-formed HTTP user agent of the reader.
248+
*/
249+
NSString * userAgent(void) {
250+
NSString *osVersion;
251+
NSOperatingSystemVersion version = [NSProcessInfo processInfo].operatingSystemVersion;
252+
osVersion = [NSString stringWithFormat:@"%ld_%ld_%ld", version.majorVersion, version.minorVersion, version.patchVersion];
253+
Preferences *prefs = [Preferences standardPreferences];
254+
NSString *name = prefs.userAgentName;
255+
return [NSString stringWithFormat:MA_DefaultUserAgentString, name, [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"], osVersion];
256+
}

Vienna/Sources/Shared/SubscriptionModel.m

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ -(NSURL *)verifiedFeedURLFromURL:(NSURL *)rssFeedURL
4646
__block NSURL * myURL;
4747
// semaphore with count equal to zero for synchronizing completion of work
4848
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
49-
NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithURL:rssFeedURL
49+
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
50+
config.HTTPAdditionalHeaders = @{@"User-Agent": userAgent()};
51+
NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
52+
NSURLSessionDataTask *task = [session dataTaskWithURL:rssFeedURL
5053
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
5154
if (error || (((NSHTTPURLResponse *)response).statusCode != 200)) {
5255
myURL = rssFeedURL;

0 commit comments

Comments
 (0)