diff --git a/android/src/com/mapswithme/maps/downloader/DownloadChunkTask.java b/android/src/com/mapswithme/maps/downloader/DownloadChunkTask.java index ece168a772..0eb523025a 100644 --- a/android/src/com/mapswithme/maps/downloader/DownloadChunkTask.java +++ b/android/src/com/mapswithme/maps/downloader/DownloadChunkTask.java @@ -171,10 +171,13 @@ class DownloadChunkTask extends AsyncTask final int err = urlConnection.getResponseCode(); // @TODO We can handle redirect (301, 302 and 307) here and display redirected page to user, // to avoid situation when downloading is always failed by "unknown" reason - if (err != HttpURLConnection.HTTP_OK && err != HttpURLConnection.HTTP_PARTIAL) + // When we didn't ask for chunks, code should be 200 + // When we asked for a chunk, code should be 206 + final boolean isChunk = !(m_beg == 0 && m_end < 0); + if ((isChunk && err != HttpURLConnection.HTTP_PARTIAL) || (!isChunk && err != HttpURLConnection.HTTP_OK)) { // we've set error code so client should be notified about the error - m_httpErrorCode = err; + m_httpErrorCode = FILE_SIZE_CHECK_FAILED; Log.w(TAG, "Error for " + urlConnection.getURL() + ": Server replied with code " + err + ", aborting download."); return false; } diff --git a/platform/http_thread_apple.mm b/platform/http_thread_apple.mm index 8993238795..2059c31b37 100644 --- a/platform/http_thread_apple.mm +++ b/platform/http_thread_apple.mm @@ -99,6 +99,7 @@ } /// We cancel and don't support any redirects to avoid data corruption +/// @TODO Display content to user - router is redirecting us somewhere -(NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse @@ -140,11 +141,14 @@ { NSInteger const statusCode = [(NSHTTPURLResponse *)response statusCode]; LOG(LDEBUG, ("Got response with status code", statusCode)); - if (statusCode < 200 || statusCode > 299) + // When we didn't ask for chunks, code should be 200 + // When we asked for a chunk, code should be 206 + bool const isChunk = !(m_begRange == 0 && m_endRange < 0); + if ((isChunk && statusCode != 206) || (!isChunk && statusCode != 200)) { - LOG(LWARNING, ("Received HTTP error, canceling download", statusCode)); + LOG(LWARNING, ("Received invalid HTTP status code, canceling download", statusCode)); [m_connection cancel]; - m_callback->OnFinish(statusCode, m_begRange, m_endRange); + m_callback->OnFinish(-4, m_begRange, m_endRange); return; } else if (m_expectedSize > 0) @@ -164,7 +168,6 @@ m_callback->OnFinish(-2, m_begRange, m_endRange); return; } - // @TODO Else display content to user - router is redirecting us somewhere } } else diff --git a/platform/http_thread_qt.cpp b/platform/http_thread_qt.cpp index 936ab1c1a5..b2a31f8d59 100644 --- a/platform/http_thread_qt.cpp +++ b/platform/http_thread_qt.cpp @@ -84,7 +84,10 @@ void HttpThread::OnHeadersReceived() return; int const httpStatusCode = m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - if (httpStatusCode < 200 || httpStatusCode > 299) + // When we didn't ask for chunks, code should be 200 + // When we asked for a chunk, code should be 206 + bool const isChunk = !(m_begRange == 0 && m_endRange < 0); + if ((isChunk && httpStatusCode != 206) || (!isChunk && httpStatusCode != 200)) { LOG(LWARNING, ("Http request to", m_reply->url().toEncoded().constData(), "aborted with HTTP code", httpStatusCode)); m_reply->abort();