void MythHttpHandler::ResponseHeaderReceived(const QHttpResponseHeader &resp) { QMutexLocker locker(&m_lock); LOG(VB_NETWORK, LOG_DEBUG, LOC + QString("ResponseHeaderReceived(%1,%2) url: %3") .arg(resp.statusCode()).arg(resp.reasonPhrase()) .arg(m_cur_url.toString())); m_cur_status_id = resp.statusCode(); m_cur_status_str = resp.reasonPhrase(); }
/** * Checks for the status code and aborts the request if needed. */ void TextBrowser::onResponseHeaderReceived(const QHttpResponseHeader &responseHeader) { if (responseHeader.statusCode() != 200) { stateChanged(tr("Download failed: %1.").arg(responseHeader.reasonPhrase())); d->http->abort(); } }
void SmugMug::WebService::_slotHttpReadyRead (const QHttpResponseHeader &resp) { QHttp &theHttp = (_ssl ? _https : _http); if (resp.statusCode () != 200) { QString msg = QString ("[%1] %2").arg (resp.statusCode ()).arg (resp.reasonPhrase ()); _logHttpError (msg); theHttp.abort(); } else { const qint64 MaxLen (theHttp.bytesAvailable ()); if (MaxLen) { char *buffer = new char [MaxLen+1]; memset (buffer, 0, MaxLen+1); qint64 count = theHttp.read (buffer, MaxLen); _dataIn.append (buffer); delete [] buffer; buffer = 0; qDebug () << "Read Ready: " << count << " of " << MaxLen; } } }
void HttpGet::httpResponseHeader(const QHttpResponseHeader &resp) { // if there is a network error abort all scheduled requests for // this download m_response = resp.statusCode(); // 301 -- moved permanently // 302 -- found // 303 -- see other // 307 -- moved temporarily // in all cases, header: location has the correct address so we can follow. if(m_response == 301 || m_response == 302 || m_response == 303 || m_response == 307) { //abort without sending any signals http.blockSignals(true); http.abort(); http.blockSignals(false); // start new request with new url qDebug() << "[HTTP] response =" << m_response << "- following"; getFile(resp.value("location") + m_query); } else if(m_response != 200) { // all other errors are fatal. http.abort(); qDebug() << "[HTTP] Response error:" << m_response << resp.reasonPhrase(); } }
void FileDownloader::readResponseHeader(const QHttpResponseHeader &responseHeader) { if (responseHeader.statusCode() != 200) { emit downloadFailed(responseHeader.reasonPhrase()); http_request_aborted = true; hide(); http->abort(); return; } }
void HttpEngine::handleUploadHeaders(QHttpResponseHeader header) { if(header.statusCode() != 200) throw header.reasonPhrase(); qint64 clen = header.value("content-length").toLongLong(); while(m_strResponse.size() < clen) m_strResponse += m_pRemote->read(1024); emit finished(false); }
void SmugMug::WebService::_slotDownloadHttpReadyRead (const QHttpResponseHeader &resp) { if (_downloadId) { qDebug () << "_slotDownloadHttpReadyRead" << resp.statusCode () << resp.reasonPhrase (); if (resp.statusCode () != 200) { qWarning () << "---- Download Http Error -----------------------------------"; qWarning () << "Response Reason:" << resp.reasonPhrase () << endl << "Request:" << _downloadHttp.currentRequest ().path () << endl << "Bytes returned:" << _downloadHttp.bytesAvailable () << endl << "-----------------------------------------------------" << endl; _downloadAborted = true; _downloadHttp.abort(); } } }
void HttpFileReceiver::readResponseHeader(const QHttpResponseHeader &responseHeader) { if ( responseHeader.statusCode() >= 400 ) { fetcher->httpRequestAborted = true; QString detailedError( "HttpFileReceiver::readReasponseHeader:- status code: %1 " "reason phrase: %2" ); detailedError = detailedError.arg( responseHeader.statusCode() ) .arg( responseHeader.reasonPhrase() ); fetcher->error = detailedError; } }
void SimpleHttp::readResponseHeader(const QHttpResponseHeader &responseHeader) { qDebug("SimpleHttp::readResponseHeader: statusCode: %d", responseHeader.statusCode()); if (responseHeader.statusCode() == 301) { QString new_url = responseHeader.value("Location"); qDebug("SimpleHttp::readResponseHeader: Location: '%s'", new_url.toLatin1().constData()); download(new_url); } else if (responseHeader.statusCode() == 302) { QString location = responseHeader.value("Location"); qDebug("SimpleHttp::readResponseHeader: Location: '%s'", location.toLatin1().constData()); /* http_get_id = get( location ); */ download(location); } else if (responseHeader.statusCode() != 200) { qDebug("SimpleHttp::readResponseHeader: error: '%s'", responseHeader.reasonPhrase().toLatin1().constData()); emit downloadFailed(responseHeader.reasonPhrase()); abort(); } }
void OracleImporter::readResponseHeader(const QHttpResponseHeader &responseHeader) { switch (responseHeader.statusCode()) { case 200: case 301: case 302: case 303: case 307: break; default: QMessageBox::information(0, tr("HTTP"), tr("Download failed: %1.").arg(responseHeader.reasonPhrase())); http->abort(); deleteLater(); } }
void HttpCore::readResponseHeader(const QHttpResponseHeader &responseHeader){ switch (responseHeader.statusCode()) { case 200: // Ok case 301: // Moved Permanently case 303: // See Other case 307: // Temporary Redirect // these are not error conditions break; default: emit(requestError(tr("Download failed: %1.").arg(responseHeader.reasonPhrase())));; this->aborted=true; http->abort(); } return; }
void UpgradeCheck::readResponseHeader(const QHttpResponseHeader &responseHeader) { switch (responseHeader.statusCode()) { case 200: // Ok case 301: // Moved Permanently case 302: // Found case 303: // See Other case 307: // Temporary Redirect // these are not error conditions break; default: QMessageBox::information(0, tr("HTTP"), tr("Download failed: %1.") .arg(responseHeader.reasonPhrase())); httpRequestAborted = true; http->abort(); } }
void HttpThread::readResponseHeader(QHttpResponseHeader const& responseHeader) { qDebug() << "httpResponseHeader" << responseHeader.statusCode(); switch (responseHeader.statusCode()) { case 200: // Ok case 301: // Moved Permanently case 302: // Found case 303: // See Other case 307: // Temporary Redirect break; // these are not error conditions default: m_errorMessage = "HTTP request failed: " + responseHeader.reasonPhrase(); qDebug() << "Error message:" << m_errorMessage; m_terminate = true; m_httpActive = false; m_http->abort(); } }
void DownloadHandler::readResponseHeader( const QHttpResponseHeader &responseHeader ) { const QString contentType("Content-Type"); #if USE_TRACE TRACESTART(DownloadHandler::readResponseHeader) #endif if( (responseHeader.statusCode() >= 300) && (responseHeader.statusCode() < 400) ) { TheMagic *magic = new TheMagic( *mpTheMagic ); magic->mURL = responseHeader.value("location"); mpMagicQueue->addMagic( magic ); mpTheMagic->fail(); } else if( responseHeader.statusCode() != 200 ) { errorMessage( mpTheMagic->mURL + ":" + QString::number( responseHeader.statusCode() ) + " " + responseHeader.reasonPhrase() ); mpTheMagic->fail(); } if( responseHeader.hasContentType() ) { mpTheMagic->setContentType( responseHeader.contentType() ); } const QString setCookie("Set-Cookie"); QList<QPair<QString, QString> > values( responseHeader.values() ); for( int i = 0; i < values.size(); i++ ) { if( !QString::compare(values.at(i).first, setCookie, Qt::CaseInsensitive) ) { #if USE_TRACE TRACEMSG << values.at(i).second; #endif mCookieJar.store( values.at(i).second ); } } }
/****************************************************************************** downloadDone ******************************************************************************/ void CAutoUpdater::downloadDone( int requestId, bool error) { if (requestId != mHttpId) { return; } Q_ASSERT(mTransport); QHttpResponseHeader header = mTransport->lastResponse(); int statusCode = header.statusCode(); //Successfull response is 2xx if (statusCode < 200 || statusCode >= 300 ) error = true; if (mCancelled) { LOG(3, "Download of update cancelled. Not emitting any signals.\n"); mFile.close(); mTransport->deleteLater(); return; } if (error) { QString errorString = header.reasonPhrase(); // Something went wrong LOG(2, "Download of component failed. Error: " << statusCode << " - " << errorString << "\n"); mFile.close(); mTransport->deleteLater(); emit updateDownloadDone(true, QString(tr("Download failed ( %1 - %2 )")). arg(statusCode). arg(errorString)); } else { // Everything's fine CComponentInfo& current = *mVecDownloads.at(mnCurrentDownload); QString installerPath = mFile.fileName(); mFile.close(); mTransport->deleteLater(); if ( current.GetSize() > 0 && ( current.GetSize() != mFile.size() ) ) { // Something went wrong LOG(2, "Download of component failed. Expected size: " << current.GetSize() << " - size of downloaded file: " << mFile.size() << "\n"); emit updateDownloadDone(true, QString(tr("The update servers are busy. Please try again later."))); return; } #ifndef WIN32 if ( current.GetURLFileExt() == "bz2" ) { QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) ); QStringList args; args << "xfj"; args << installerPath; QProcess proc( this ); #ifdef Q_WS_MAC QDir d = QDir( QCoreApplication::applicationDirPath() ); d.cdUp(); proc.setWorkingDirectory( d.absolutePath() ); #else proc.setWorkingDirectory( QCoreApplication::applicationDirPath() ); #endif proc.start( "tar", args ); proc.waitForFinished( 60000 ); QFile( installerPath ).remove(); QApplication::restoreOverrideCursor(); if ( mnCurrentDownload < ( mnDownloadTasks - 1 ) ) { downloadNext(); } else { emit updateDownloadDone( false ); } } #endif #ifdef WIN32 if (current.GetURLFileExt() == "exe") { // Sometimes you've got to be pragmatic if (current.IsApp()) { // Install this separately msAppDLPath = installerPath; mbRestartNeeded = true; if (mnCurrentDownload < (mnDownloadTasks - 1)) { downloadNext(); } else { emit updateDownloadDone(false); } return; } QString installDir = QDir::toNativeSeparators( current.GetInstallPath() ); QDir dir( installDir ); if ( !dir.exists() ) { LOGL( 3, "Install dir '" << installDir << "' didn't exist. Creating it." ); bool success = dir.mkdir( installDir ); if ( !success ) { LOGL( 3, "Folder creation failed" ); } } WCHAR buf[MAX_PATH]; DWORD res = GetShortPathNameW( reinterpret_cast<LPCWSTR>( installDir.utf16() ), buf, MAX_PATH ); if ( res == 0 ) { DWORD err = GetLastError(); LOGL( 2, "Couldn't convert path to short version, using long. System error: " << err ); } else { installDir = QString::fromUtf16( reinterpret_cast<const ushort*>( buf ) ); } installDir = "\"" + installDir + "\""; // HACK! Turning into a bit of a hackfest this. Seeing as all the // exes we use so far are Inno Setup ones, we can tack on // a "/DIR" param with the correct plugin path (which we can't // know at installer compile time) onto the end of the args string. // This will most probably die horribly if run on a non-Inno installer. QString installArgs = current.GetInstallArgs() + " /DIR=" + installDir; LOG(3, "Running '" << installerPath << " " << installArgs << "'\n"); // Run installer // Must use ShellExecute because otherwise the elevation dialog // doesn't appear when launching the installer on Vista. SHELLEXECUTEINFOW sei; memset(&sei, 0, sizeof(sei)); sei.cbSize = sizeof(sei); sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_DDEWAIT; sei.hwnd = GetForegroundWindow(); sei.lpVerb = L"open"; sei.lpFile = reinterpret_cast<LPCWSTR>(installerPath.utf16()); sei.lpParameters = reinterpret_cast<LPCWSTR>(installArgs.utf16()); sei.nShow = SW_SHOWNORMAL; BOOL bOK = ShellExecuteExW(&sei); if (bOK) { QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); WaitForSingleObject(sei.hProcess, 5000); CloseHandle(sei.hProcess); QApplication::restoreOverrideCursor(); } else { LOG(1, "Couldn't ShellExecuteEx " << installerPath << " " << installArgs << ". GetLastError: " << GetLastError() << "\n"); QString msg = tr("Failed to install '") + installerPath + tr("'."); emit updateDownloadDone(true, msg); return; } if (mnCurrentDownload < (mnDownloadTasks - 1)) { downloadNext(); } else { emit updateDownloadDone(false); } } else if (current.GetURLFileExt() == "dll") { // Do something to enable uninstalling dlls here Q_ASSERT_X(false, "CAutoUpdate::downloadDone", "Not implemented."); } #endif // WIN32 } // end if error }
void HttpEngine::handleDownloadHeaders(QHttpResponseHeader header) { switch(header.statusCode()) { case 200: { if(m_file.pos() && !header.hasKey("content-range")) { if(m_nSegmentStart < 0) { // resume not supported m_file.resize(0); m_file.seek(0); emit statusMessage(tr("Resume not supported")); } else throw tr("Segmentation not supported by server"); } } case 206: // data will follow { bool bChunked = false; if(header.value("transfer-encoding").compare("chunked",Qt::CaseInsensitive) == 0) bChunked = true; else { m_nToTransfer = header.value("content-length").toLongLong(); emit receivedSize(m_nToTransfer+m_nResume); } if(header.hasKey("content-disposition")) { QString disp = header.value("content-disposition"); int pos = disp.indexOf("filename="); if(pos != -1) { QString name = disp.mid(pos+9); if(name.startsWith('"') && name.endsWith('"')) name = name.mid(1, name.size()-2); emit renamed(name); } } dataCycle(bChunked); emit finished(false); break; } case 301 ... 399: // redirect emit redirected(header.value("location")); break; case 416: // Requested Range Not Satisfiable m_strError = tr("Requested Range Not Satisfiable - the file has probably already been downloaded"); emit finished(false); break; default: // error throw header.reasonPhrase(); } }
void DBoxFE_ProfileWizard::readResponseHeader( const QHttpResponseHeader &responseHeader ) { if ( responseHeader.statusCode() != 200 ) { QMessageBox::information( this, dbfe->winTitle(), tr( "Download failed: %1." ).arg( responseHeader.reasonPhrase() ) ); httpRequestAborted = true; m_http->abort(); return ; } }
void HttpInput::onHttpResponseHeader( const QHttpResponseHeader& resp ) { m_timeoutTimer.stop(); int respCode = resp.statusCode(); QString respPhrase = resp.reasonPhrase(); QString errorMsg = "\n\nStreamer error code: " + QString::number( respCode ) + "\nReason: " + respPhrase; // Redirects handled by RedirectHttp class if ( respCode != 200 && respCode != 301 && respCode != 302 && respCode != 307 ) { LOGL( 2, errorMsg ) } switch( resp.statusCode() ) { case 200: { // Success } break; case 403: { // INVALID_TICKET = "HTTP/1.1 403 Invalid ticket"; // INVALID_AUTH = "HTTP/1.1 403 Invalid authorization"; // TODO: better error messages if ( respPhrase == "Invalid ticket" ) emit error( Radio_InvalidUrl, m_genericAsOfYetUndiagnosedStreamerError + errorMsg ); else emit error( Radio_InvalidAuth, tr( "Invalid authorisation." ) + errorMsg ); } break; case 404: { // Should try different URL if we have one. // NO_TRACK_FOUND = "HTTP/1.1 404 Track not found"; // NO_TRACK_AVAILABLE = "HTTP/1.1 404 Track not available" // = "HTTP/1.1 404 Track invalid" emit error( Radio_TrackNotFound, tr( "This stream is currently not available. Please try again later." ) + errorMsg ); } break; case 503: { // EXCEEDED_SKIP_LIMIT = "HTTP/1.1 503 Skip limit exceeded" // UNEXPECTED_ERROR = "HTTP/1.1 503 Unexpected Error"; if ( resp.reasonPhrase() == "Skip limit exceeded" ) emit error( Radio_SkipLimitExceeded, tr( "Skip limit exceeded." ) + errorMsg ); else emit error( Radio_UnknownError, m_genericAsOfYetUndiagnosedStreamerError + errorMsg ); } break; case 301: //Moved Permanently case 302: case 307: //Temporary Redirect { // This is now handled by the RedirectHttp class } break; default: { Q_ASSERT( !"Mischa didn't tell us about this one." ); emit error( Radio_UnknownError, m_genericAsOfYetUndiagnosedStreamerError + errorMsg ); } } }
/*---------------------------------------------------------------------------*/ QVariant HttpRecognizer::comment( IConnection* connection ) { Q_ASSERT (connection); if (!mConnections.contains( connection->networkInfo() )) return "No comment yet"; const HttpConnection con = mConnections.value( connection->networkInfo() ); const QHttpRequestHeader request = con.lastRequestHeader(); const QHttpResponseHeader response = con.lastResponseHeader(); return request.method() + " " + request.value( "host" ) + request.path() + (response.isValid() ? "\nHTTP " + QString::number( response.statusCode() ) + " " + response.reasonPhrase() : "" ); }
void HttpComms::headerReceived(const QHttpResponseHeader &resp) { m_statusCode = resp.statusCode(); m_responseReason = resp.reasonPhrase(); QString sidkey = "set-cookie"; if (resp.hasKey(sidkey)) { QRegExp rx("PHPSESSID=(.+);"); rx.setMinimal(true); rx.setCaseSensitivity(Qt::CaseInsensitive); if (rx.indexIn(resp.value(sidkey)) >= 0) { m_cookie = "PHPSESSID=" + rx.cap(1); VERBOSE(VB_NETWORK, QString("HttpComms found cookie: %1").arg(m_cookie)); } } VERBOSE(VB_NETWORK, QString("Got HTTP response: %1:%2") .arg(m_statusCode) .arg(m_responseReason)); VERBOSE(VB_NETWORK, QString("Keys: %1") .arg(resp.keys().join(",") )); if (resp.statusCode() >= 300 && resp.statusCode() <= 400) { // redirection QString uri = resp.value("LOCATION"); VERBOSE(VB_NETWORK, QString("Redirection to: '%1'").arg(uri)); m_redirectedURL = resp.value("LOCATION"); m_authNeeded = false; } else if ((resp.statusCode() == 401)) { // Toggle the state of our authentication pending flag // if we've gotten this after having tried to authenticate // once then we've failed authentication and turning the pending off will allow us to exit. m_authNeeded = !m_authNeeded; if (m_authNeeded) { QString authHeader(resp.value("www-authenticate")); if (authHeader.startsWith("Digest") ) { if (!createDigestAuth(false, authHeader, &m_curRequest) ) { m_authNeeded = false; return; } } else { QString sUser(m_webCredentials.user + ':' + m_webCredentials.pass); QByteArray auth = QCodecs::base64Encode(sUser.toLocal8Bit()); m_curRequest.setValue( "Authorization", QString( "Basic " ).append( auth ) ); } if (m_timer) { m_timer->stop(); m_timer->setSingleShot(true); m_timer->start(m_timeoutInterval); } // Not sure if it's possible to receive a session ID or other cookie // before authenticating or not. if (!m_cookie.isEmpty()) { m_curRequest.setValue("Cookie", m_cookie); } http->request(m_curRequest); } } else { m_authNeeded = false; } }