diff --git a/modules/juce_core/native/juce_mac_Network.mm b/modules/juce_core/native/juce_mac_Network.mm index d45357bcf0..ed695b5d7e 100644 --- a/modules/juce_core/native/juce_mac_Network.mm +++ b/modules/juce_core/native/juce_mac_Network.mm @@ -622,6 +622,7 @@ public: connection (nil), data ([[NSMutableData data] retain]), headers (nil), + nsUrlErrorCode (0), statusCode (0), initialised (false), hasFailed (false), @@ -745,6 +746,7 @@ public: void didFailWithError (NSError* error) { DBG (nsStringToJuce ([error description])); ignoreUnused (error); + nsUrlErrorCode = [error code]; hasFailed = true; initialised = true; signalThreadShouldExit(); @@ -789,6 +791,7 @@ public: NSURLConnection* connection; NSMutableData* data; NSDictionary* headers; + NSInteger nsUrlErrorCode; int statusCode; bool initialised, hasFailed, hasFinished; const int numRedirectsToFollow; @@ -878,16 +881,24 @@ public: connection = nullptr; } - bool connect (WebInputStream::Listener* webInputListener) + bool connect (WebInputStream::Listener* webInputListener, int attemptNumber = 0) { - createConnection (); + createConnection(); if (! connection->start (owner, webInputListener)) { + // Workaround for deployment targets below 10.10 where HTTPS POST requests with keep-alive fail with the NSURLErrorNetworkConnectionLost error code. + #if ! (JUCE_IOS || (defined (__MAC_OS_X_VERSION_MIN_REQUIRED) && defined (__MAC_10_10) && __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_10)) + if (attemptNumber == 0 && connection->nsUrlErrorCode == NSURLErrorNetworkConnectionLost) + { + connection = nullptr; + return connect (webInputListener, ++attemptNumber); + } + #endif + connection = nullptr; return false; } - if (connection != nullptr && connection->headers != nil) { statusCode = connection->statusCode;