void QNetworkReplyHandler::finish() { ASSERT(m_replyWrapper && m_replyWrapper->reply() && !wasAborted()); ResourceHandleClient* client = m_resourceHandle->client(); if (!client) { m_replyWrapper = 0; return; } if (m_replyWrapper->wasRedirected()) { m_replyWrapper = 0; m_queue.push(&QNetworkReplyHandler::start); return; } if (!m_replyWrapper->reply()->error() || shouldIgnoreHttpError(m_replyWrapper->reply(), m_replyWrapper->responseContainsData())) client->didFinishLoading(m_resourceHandle, 0); else { QUrl url = m_replyWrapper->reply()->url(); int httpStatusCode = m_replyWrapper->reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if (httpStatusCode) { ResourceError error("HTTP", httpStatusCode, url.toString(), m_replyWrapper->reply()->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString()); client->didFail(m_resourceHandle, error); } else { ResourceError error("QtNetwork", m_replyWrapper->reply()->error(), url.toString(), m_replyWrapper->reply()->errorString()); client->didFail(m_resourceHandle, error); } } m_replyWrapper = 0; }
void QNetworkReplyHandler::finish() { m_shouldFinish = (m_loadMode != LoadNormal); if (m_shouldFinish) return; sendResponseIfNeeded(); if (!m_resourceHandle) return; ResourceHandleClient* client = m_resourceHandle->client(); if (!client) { m_reply->deleteLater(); m_reply = 0; return; } QNetworkReply* oldReply = m_reply; if (m_redirected) { resetState(); start(); } else if (!m_reply->error() || ignoreHttpError(m_reply, m_responseDataSent)) { client->didFinishLoading(m_resourceHandle); } else { QUrl url = m_reply->url(); int httpStatusCode = m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if (httpStatusCode) { ResourceError error("HTTP", httpStatusCode, url.toString(), m_reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString()); client->didFail(m_resourceHandle, error); } else { ResourceError error("QtNetwork", m_reply->error(), url.toString(), m_reply->errorString()); client->didFail(m_resourceHandle, error); } } oldReply->deleteLater(); if (oldReply == m_reply) m_reply = 0; }
// Called at the end of the message, with all the necessary about the last informations. // Doesn't get called for redirects. static void finishedCallback(SoupSession *session, SoupMessage* msg, gpointer data) { RefPtr<ResourceHandle> handle = adoptRef(static_cast<ResourceHandle*>(data)); // TODO: maybe we should run this code even if there's no client? if (!handle) return; ResourceHandleInternal* d = handle->getInternal(); ResourceHandleClient* client = handle->client(); if (!client) return; if (d->m_cancelled) return; if (SOUP_STATUS_IS_TRANSPORT_ERROR(msg->status_code)) { char* uri = soup_uri_to_string(soup_message_get_uri(msg), false); ResourceError error(g_quark_to_string(SOUP_HTTP_ERROR), msg->status_code, uri, String::fromUTF8(msg->reason_phrase)); g_free(uri); client->didFail(handle.get(), error); return; } if (msg->status_code == SOUP_STATUS_UNAUTHORIZED) { fillResponseFromMessage(msg, &d->m_response); client->didReceiveResponse(handle.get(), d->m_response); // WebCore might have cancelled the job in the while if (d->m_cancelled) return; if (msg->response_body->data) client->didReceiveData(handle.get(), msg->response_body->data, msg->response_body->length, true); } client->didFinishLoading(handle.get()); }
// Called at the end of the message, with all the necessary about the last informations. // Doesn't get called for redirects. static void finishedCallback(SoupSession *session, SoupMessage* msg, gpointer data) { ResourceHandle* handle = static_cast<ResourceHandle*>(data); // TODO: maybe we should run this code even if there's no client? if (!handle) return; ResourceHandleInternal* d = handle->getInternal(); // The message has been handled. d->m_msg = NULL; ResourceHandleClient* client = handle->client(); if (!client) return; if (d->m_cancelled) return; if (SOUP_STATUS_IS_TRANSPORT_ERROR(msg->status_code)) { char* uri = soup_uri_to_string(soup_message_get_uri(msg), FALSE); ResourceError error("webkit-network-error", ERROR_TRANSPORT, uri, String::fromUTF8(msg->reason_phrase)); g_free(uri); client->didFail(handle, error); return; } else if (!SOUP_STATUS_IS_SUCCESSFUL(msg->status_code)) { fillResponseFromMessage(msg, &d->m_response); client->didReceiveResponse(handle, d->m_response); // WebCore might have cancelled the job in the while if (d->m_cancelled) return; if (msg->response_body->data) client->didReceiveData(handle, msg->response_body->data, msg->response_body->length, true); } client->didFinishLoading(handle); }
void QNetworkReplyHandler::finish() { ASSERT(m_replyWrapper && m_replyWrapper->reply() && !wasAborted()); ResourceHandleClient* client = m_resourceHandle->client(); if (!client) { m_replyWrapper = nullptr; return; } if (m_replyWrapper->wasRedirected()) { m_replyWrapper = nullptr; m_queue.push(&QNetworkReplyHandler::start); return; } if (!m_replyWrapper->reply()->error() || shouldIgnoreHttpError(m_replyWrapper->reply(), m_replyWrapper->responseContainsData())) client->didFinishLoading(m_resourceHandle, 0); else client->didFail(m_resourceHandle, errorForReply(m_replyWrapper->reply())); m_replyWrapper = nullptr; }
void QNetworkReplyHandler::timeout() { if (!m_replyWrapper || wasAborted()) return; // The request is already finished, but is probably just waiting in the queue to get processed. // In this case we ignore the timeout and proceed as normal. if (m_replyWrapper->isFinished()) return; ResourceHandleClient* client = m_resourceHandle->client(); if (!client) { m_replyWrapper.clear(); return; } ASSERT(m_replyWrapper->reply()); ResourceError timeoutError("QtNetwork", QNetworkReply::TimeoutError, m_replyWrapper->reply()->url().toString(), "Request timed out"); timeoutError.setIsTimeout(true); client->didFail(m_resourceHandle, timeoutError); m_replyWrapper.clear(); }
void MyResourceLoader::loadFile(const String& file) { LOGD("Loading file (%s) ...", file.latin1().data()); FILE* f = fopen(file.latin1().data(), "r"); ResourceHandleClient* client = m_handle->client(); if (!f) { client->didFail(m_handle, ResourceError("", -14, file, "Could not open file")); } else { ResourceResponse response; response.setTextEncodingName("utf-8"); response.setMimeType(mimeTypeForExtension(file)); client->didReceiveResponse(m_handle, response); char buf[512]; while (true) { int res = fread(buf, 1, sizeof(buf), f); if (res <= 0) break; client->didReceiveData(m_handle, buf, res, 0); } fclose(f); client->didFinishLoading(m_handle, 0); } }
void ResourceHandleInternal::didFail(WebURLLoader*, const WebURLError& error) { ASSERT(m_client); m_state = ConnectionStateFailed; m_client->didFail(m_owner, error); }