Adapted for NSURLSession.