I have a timeOutInterval set to 30 seconds on all my requests via this code:
class DefaultAlamofireSession: Alamofire.Session {
static let shared: DefaultAlamofireSession = {
let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = 30
configuration.timeoutIntervalForResource = 30
return DefaultAlamofireSession(configuration: configuration)
}()
}
While testing, I noticed that only my GET requests get timed out at 30 seconds. My POST requests are still using the default interval which is 60 seconds.
Can anyone explain why and possibly tell me how I can make the POST requests also time out at 60 seconds?
Thanks a lot, Paprika
URLSessionConfiguration.timeoutIntervalForRequestdoes not do what you think it does. From Apple's docs:So that property only controls the timeout between chunks of response
Data. That's not typically what you want. Instead, you want to set theURLRequest.timeoutIntervaldirectly, which does more of what you want.As you can see, this timeout applies to the connection attempt, which is what most people think of as a request's timeout.
You can customize this value in Alamofire by applying a
RequestAdapterto your customSession. Or, you can use therequestModifierclosure that available on the variousrequest*methods.