http.cc
来自「konqueror3 embedded版本, KDE环境下的当家浏览器的嵌入式版」· CC 代码 · 共 2,361 行 · 第 1/5 页
CC
2,361 行
if (u.path().isEmpty()) { KURL newUrl(u); newUrl.setPath("/"); redirection(newUrl); finished(); return false; } if ( m_protocol != u.protocol().latin1() ) { short unsigned int oldDefaultPort = m_iDefaultPort; m_protocol = u.protocol().latin1(); reparseConfiguration(); if ( m_iDefaultPort != oldDefaultPort && m_request.port == oldDefaultPort ) m_request.port = m_iDefaultPort; } resetSessionSettings(); return true;}void HTTPProtocol::retrieveContent( bool dataInternal /* = false */ ){ kdDebug (7113) << "(" << m_pid << ") HTTPProtocol::retrieveContent " << endl; if ( !retrieveHeader( false ) ) { if ( m_bError ) return; } else { if ( !readBody( dataInternal ) && m_bError ) return; } httpClose(m_bKeepAlive); // if data is required internally, don't finish, // it is processed before we finish() if ( !dataInternal ) { if ((m_responseCode == 204) && ((m_request.method == HTTP_GET) || (m_request.method == HTTP_POST))) error(ERR_NO_CONTENT, ""); else finished(); }}bool HTTPProtocol::retrieveHeader( bool close_connection ){ kdDebug (7113) << "(" << m_pid << ") HTTPProtocol::retrieveHeader " << endl; while ( 1 ) { if (!httpOpen()) return false; resetResponseSettings(); if (!readHeader()) { if ( m_bError ) return false; if (m_bIsTunneled) { kdDebug(7113) << "(" << m_pid << ") Re-establishing SSL tunnel..." << endl; httpCloseConnection(); } } else { // Do not save authorization if the current response code is // 4xx (client error) or 5xx (server error). kdDebug(7113) << "(" << m_pid << ") Previous Response: " << m_prevResponseCode << endl; kdDebug(7113) << "(" << m_pid << ") Current Response: " << m_responseCode << endl; if (isSSLTunnelEnabled() && m_bIsSSL && !m_bUnauthorized && !m_bError) { // If there is no error, disable tunneling if ( m_responseCode < 400 ) { kdDebug(7113) << "(" << m_pid << ") Unset tunneling flag!" << endl; setEnableSSLTunnel( false ); m_bIsTunneled = true; // Reset the CONNECT response code... m_responseCode = m_prevResponseCode; continue; } else { if ( !m_request.bErrorPage ) { kdDebug(7113) << "(" << m_pid << ") Sending an error message!" << endl; error( ERR_UNKNOWN_PROXY_HOST, m_proxyURL.host() ); return false; } kdDebug(7113) << "(" << m_pid << ") Sending an error page!" << endl; } } if (m_responseCode < 400 && (m_prevResponseCode == 401 || m_prevResponseCode == 407)) saveAuthorization(); break; } } // Clear of the temporary POST buffer if it is not empty... if (!m_bufPOST.isEmpty()) { m_bufPOST.resize(0); kdDebug(7113) << "(" << m_pid << ") HTTP::retreiveHeader: Cleared POST " "buffer..." << endl; } if ( close_connection ) { httpClose(m_bKeepAlive); finished(); } return true;}void HTTPProtocol::stat(const KURL& url){ kdDebug(7113) << "(" << m_pid << ") HTTPProtocol::stat " << url.prettyURL() << endl; if ( !checkRequestURL( url ) ) return; if ( m_protocol != "webdav" && m_protocol != "webdavs" ) { QString statSide = metaData(QString::fromLatin1("statSide")); if ( statSide != "source" ) { // When uploading we assume the file doesn't exit error( ERR_DOES_NOT_EXIST, url.prettyURL() ); return; } // When downloading we assume it exists UDSEntry entry; UDSAtom atom; atom.m_uds = KIO::UDS_NAME; atom.m_str = url.fileName(); entry.append( atom ); atom.m_uds = KIO::UDS_FILE_TYPE; atom.m_long = S_IFREG; // a file entry.append( atom ); atom.m_uds = KIO::UDS_ACCESS; atom.m_long = S_IRUSR | S_IRGRP | S_IROTH; // readable by everybody entry.append( atom ); statEntry( entry ); finished(); return; }#if !defined(QT_NO_DOM) davStatList( url );#endif}#if !defined(QT_NO_DOM)void HTTPProtocol::listDir( const KURL& url ){ kdDebug(7113) << "(" << m_pid << ") HTTPProtocol::listDir " << url.url() << endl; if ( !checkRequestURL( url ) ) return; davStatList( url, false );}void HTTPProtocol::davSetRequest( const QCString& requestXML ){ // insert the document into the POST buffer, kill trailing zero byte m_bufPOST = requestXML; if (m_bufPOST.size()) m_bufPOST.truncate( m_bufPOST.size() - 1 );}void HTTPProtocol::davStatList( const KURL& url, bool stat ){ UDSEntry entry; UDSAtom atom; // check to make sure this host supports WebDAV if ( !davHostOk() ) return; // Maybe it's a disguised SEARCH... QString query = metaData("davSearchQuery"); if ( !query.isEmpty() ) { QCString request = "<?xml version=\"1.0\"?>\r\n"; request.append( "<D:searchrequest xmlns:D=\"DAV:\">\r\n" ); request.append( query.utf8() ); request.append( "</D:searchrequest>\r\n" ); davSetRequest( request ); } else { // We are only after certain features... QCString request; request = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" "<D:propfind xmlns:D=\"DAV:\">"; // insert additional XML request from the davRequestResponse metadata if ( hasMetaData( "davRequestResponse" ) ) request += metaData( "davRequestResponse" ).utf8(); else { // No special request, ask for default properties request += "<D:prop>" "<D:creationdate/>" "<D:getcontentlength/>" "<D:displayname/>" "<D:source/>" "<D:getcontentlanguage/>" "<D:getcontenttype/>" "<D:executable/>" "<D:getlastmodified/>" "<D:getetag/>" "<D:supportedlock/>" "<D:lockdiscovery/>" "<D:resourcetype/>" "</D:prop>"; } request += "</D:propfind>"; davSetRequest( request ); } // WebDAV Stat or List... m_request.method = query.isEmpty() ? DAV_PROPFIND : DAV_SEARCH; m_request.query = QString::null; m_request.cache = CC_Reload; m_request.doProxy = m_bUseProxy; m_request.davData.depth = stat ? 0 : 1; if (!stat) m_request.url.adjustPath(+1); retrieveContent( true ); // Has a redirection already been called? If so, we're done. if (m_bRedirect) { finished(); return; } QDomDocument multiResponse; multiResponse.setContent( m_bufWebDavData, true ); bool hasResponse = false; for ( QDomNode n = multiResponse.documentElement().firstChild(); !n.isNull(); n = n.nextSibling()) { QDomElement thisResponse = n.toElement(); if (thisResponse.isNull()) continue; hasResponse = true; QDomElement href = thisResponse.namedItem( "href" ).toElement(); if ( !href.isNull() ) { entry.clear(); QString urlStr = href.text(); int encoding = remoteEncoding()->encodingMib(); if ((encoding == 106) && (!KStringHandler::isUtf8(KURL::decode_string(urlStr, 4).latin1()))) encoding = 4; // Use latin1 if the file is not actually utf-8 KURL thisURL ( urlStr, encoding ); atom.m_uds = KIO::UDS_NAME; if ( thisURL.isValid() ) { // don't list the base dir of a listDir() if ( !stat && thisURL.path(+1).length() == url.path(+1).length() ) continue; atom.m_str = thisURL.fileName(); } else { // This is a relative URL. atom.m_str = href.text(); } entry.append( atom ); QDomNodeList propstats = thisResponse.elementsByTagName( "propstat" ); davParsePropstats( propstats, entry ); if ( stat ) { // return an item statEntry( entry ); finished(); return; } else { listEntry( entry, false ); } } else { kdDebug(7113) << "Error: no URL contained in response to PROPFIND on " << url.prettyURL() << endl; } } if ( stat || !hasResponse ) { error( ERR_DOES_NOT_EXIST, url.prettyURL() ); } else { listEntry( entry, true ); finished(); }}void HTTPProtocol::davGeneric( const KURL& url, KIO::HTTP_METHOD method ){ kdDebug(7113) << "(" << m_pid << ") HTTPProtocol::davGeneric " << url.url() << endl; if ( !checkRequestURL( url ) ) return; // check to make sure this host supports WebDAV if ( !davHostOk() ) return; // WebDAV method m_request.method = method; m_request.query = QString::null; m_request.cache = CC_Reload; m_request.doProxy = m_bUseProxy; retrieveContent( false );}#endifint HTTPProtocol::codeFromResponse( const QString& response ){ int firstSpace = response.find( ' ' ); int secondSpace = response.find( ' ', firstSpace + 1 ); return response.mid( firstSpace + 1, secondSpace - firstSpace - 1 ).toInt();}#if !defined(QT_NO_DOM)void HTTPProtocol::davParsePropstats( const QDomNodeList& propstats, UDSEntry& entry ){ QString mimeType; UDSAtom atom; bool foundExecutable = false; bool isDirectory = false; uint lockCount = 0; uint supportedLockCount = 0; for ( uint i = 0; i < propstats.count(); i++) { QDomElement propstat = propstats.item(i).toElement(); QDomElement status = propstat.namedItem( "status" ).toElement(); if ( status.isNull() ) { // error, no status code in this propstat kdDebug(7113) << "Error, no status code in this propstat" << endl; return; } int code = codeFromResponse( status.text() ); if ( code != 200 ) { kdDebug(7113) << "Warning: status code " << code << " (this may mean that some properties are unavailable" << endl; continue; } QDomElement prop = propstat.namedItem( "prop" ).toElement(); if ( prop.isNull() ) { kdDebug(7113) << "Error: no prop segment in this propstat." << endl; return; } if ( hasMetaData( "davRequestResponse" ) ) { atom.m_uds = KIO::UDS_XML_PROPERTIES; QDomDocument doc; doc.appendChild(prop); atom.m_str = doc.toString(); entry.append( atom ); } for ( QDomNode n = prop.firstChild(); !n.isNull(); n = n.nextSibling() ) { QDomElement property = n.toElement(); if (property.isNull()) continue; if ( property.namespaceURI() != "DAV:" ) { // break out - we're only interested in properties from the DAV namespace continue; } if ( property.tagName() == "creationdate" ) { // Resource creation date. Should be is ISO 8601 format. atom.m_uds = KIO::UDS_CREATION_TIME; atom.m_long = parseDateTime( property.text(), property.attribute("dt") ); entry.append( atom ); } else if ( property.tagName() == "getcontentlength" ) { // Content length (file size) atom.m_uds = KIO::UDS_SIZE; atom.m_long = property.text().toULong(); entry.append( atom ); } else if ( property.tagName() == "displayname" ) { // Name suitable for presentation to the user setMetaData( "davDisplayName", property.text() ); } else if ( property.tagName() == "source" ) { // Source template location QDomElement source = property.namedItem( "link" ).toElement() .namedItem( "dst" ).toElement(); if ( !source.isNull() ) setMetaData( "davSource", source.text() ); } else if ( property.tagName() == "getcontentlanguage" ) { // equiv. to Content-Language header on a GET setMetaData( "davContentLanguage", property.text() ); } else if ( property.tagName() == "getcontenttype" ) { // Content type (mime type) // This may require adjustments for other server-side webdav implementations // (tested with Apache + mod_dav 1.0.3) if ( property.text() == "httpd/unix-directory" ) { isDirectory = true; } else { mimeType = property.text(); } } else if ( property.tagName() == "executable" ) { // File executable status if ( property.text() == "T" )
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?