From 7120d7dfca136ce7938344d8ccdef56b260d8dbf Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 5 Jan 2017 16:54:00 +0000 Subject: [PATCH] Fix for HTTPS POST requests with keep-alive failing on OS X versions below 10.10 --- modules/juce_core/native/juce_mac_Network.mm | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) 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;