diff --git a/platform/http_thread_apple.mm b/platform/http_thread_apple.mm index 8f133a7742..8993238795 100644 --- a/platform/http_thread_apple.mm +++ b/platform/http_thread_apple.mm @@ -98,6 +98,24 @@ return self; } +/// We cancel and don't support any redirects to avoid data corruption +-(NSURLRequest *)connection:(NSURLConnection *)connection + willSendRequest:(NSURLRequest *)request + redirectResponse:(NSURLResponse *)redirectResponse +{ + if (!redirectResponse) + { + // Special case, system just normalizes request, it's not a real redirect + return request; + } + // In all other cases we are cancelling redirects + LOG(LWARNING, ("Canceling because of redirect from", [[[redirectResponse URL] absoluteString] UTF8String], + "to", [[[request URL] absoluteString] UTF8String])); + [connection cancel]; + m_callback->OnFinish(-3, m_begRange, m_endRange); + return nil; +} + /// @return -1 if can't decode + (int64_t) getContentRange:(NSDictionary *)httpHeader { diff --git a/platform/platform_tests/downloader_test.cpp b/platform/platform_tests/downloader_test.cpp index 8648a9f204..741e2c8f87 100644 --- a/platform/platform_tests/downloader_test.cpp +++ b/platform/platform_tests/downloader_test.cpp @@ -142,11 +142,11 @@ UNIT_TEST(DownloaderSimpleGet) observer.Reset(); { - // permanent redirect success case + // We DO NOT SUPPORT redirects to avoid data corruption when downloading mwm files scoped_ptr request(HttpRequest::Get(TEST_URL_PERMANENT, onFinish, onProgress)); QCoreApplication::exec(); - observer.TestOk(); - TEST_EQUAL(request->Data(), "Test1", ()); + observer.TestFailed(); + TEST_EQUAL(request->Data().size(), 0, (request->Data())); } observer.Reset();