From 60895fc7fa21add810e35cb23ebd17272bb6dd03 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sun, 12 May 2019 07:22:33 -0500 Subject: [PATCH] Restrict Feedbin to a maximum of 1 concurrent connection to keep us under Feedbin's 250 requests per second rate limit --- Frameworks/Account/Account.swift | 2 +- .../Account/Feedbin/FeedbinAPICaller.swift | 4 +++ .../Feedbin/FeedbinAccountDelegate.swift | 27 +++++++++++++++++-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index 4b33dafa3..6fc247f3f 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -179,7 +179,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, return delegate.supportsSubFolders } - init?(dataFolder: String, type: AccountType, accountID: String, transport: Transport = URLSession.webserviceTransport()) { + init?(dataFolder: String, type: AccountType, accountID: String, transport: Transport? = nil) { switch type { case .onMyMac: diff --git a/Frameworks/Account/Feedbin/FeedbinAPICaller.swift b/Frameworks/Account/Feedbin/FeedbinAPICaller.swift index 9bce1b4d9..ef77af922 100644 --- a/Frameworks/Account/Feedbin/FeedbinAPICaller.swift +++ b/Frameworks/Account/Feedbin/FeedbinAPICaller.swift @@ -6,6 +6,10 @@ // Copyright © 2019 Ranchero Software, LLC. All rights reserved. // +// Feedbin currently has a maximum of 250 requests per second. If you begin to receive +// HTTP Response Codes of 403, you have exceeded this limit. Wait 5 minutes and your +// IP address will become unblocked and you can use the service again. + import Foundation import RSWeb diff --git a/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift b/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift index 4714e3d2a..9b6d13e68 100644 --- a/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift @@ -41,8 +41,31 @@ final class FeedbinAccountDelegate: AccountDelegate { } } - init(transport: Transport) { - caller = FeedbinAPICaller(transport: transport) + init(transport: Transport?) { + + if transport != nil { + + caller = FeedbinAPICaller(transport: transport!) + + } else { + + let sessionConfiguration = URLSessionConfiguration.default + sessionConfiguration.requestCachePolicy = .reloadIgnoringLocalCacheData + sessionConfiguration.timeoutIntervalForRequest = 60.0 + sessionConfiguration.httpShouldSetCookies = false + sessionConfiguration.httpCookieAcceptPolicy = .never + sessionConfiguration.httpMaximumConnectionsPerHost = 1 + sessionConfiguration.httpCookieStorage = nil + sessionConfiguration.urlCache = nil + + if let userAgentHeaders = UserAgent.headers() { + sessionConfiguration.httpAdditionalHeaders = userAgentHeaders + } + + caller = FeedbinAPICaller(transport: URLSession(configuration: sessionConfiguration)) + + } + } var refreshProgress = DownloadProgress(numberOfTasks: 0)