How to disable keepalive in NSURLConnection?
Asked Answered
O

1

3

Is there any way to force NSURLConnection to not reuse the current persistent connection but to create a new one ?

I am trying to defend myself from this known iOS8 keep-alive bug

If iOS 8 receives a HTTP response with a Keep-Alive header, it keeps this connection to re-use later (as it should), but it keeps it for more than the timeout parameter of the Keep-Alive header and then when a second request comes it tries to re-use a connection that has been dropped by the server.

I am looking for a way to solve this issue from Objective c rather than solving from server side.

If any third party libraries provides a way to ignore Keep-alive header then its also welcome.

This issue is somewhat related to following issues(1,2)

Any help is appreciated !

Osteogenesis answered 15/3, 2015 at 17:24 Comment(0)
P
3

The only way I found is to use CFNetwork. Higher level API such as NSURLConnection or NSURLSession's Connection header will be overwritten by system.

Pawpaw answered 20/3, 2015 at 17:9 Comment(5)
So we don't have any option to disable it as of now.Osteogenesis
no way to set value such as close for Connection in HTTP header with NSURLSession, iOS just ignores the value and always sends keep-aliveOsteogenesis
As I said in my answer, you can, with low level API such as CFNetwork.Pawpaw
will apple reject the app if we use that low level API ? Can you share the working code snippet ?Osteogenesis
Of course will not be rejected. It is public API. The code is not a snippet but really quite simply, just setting Connect header. You should read the doc.Pawpaw

© 2022 - 2024 — McMap. All rights reserved.