[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs
From: Allan Sandfeld Jensen <kde () carewolf ! com>
Date: 2007-10-15 21:41:56
Message-ID: 1192484516.820837.4164.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 725638 by carewolf:
Store all http-headers in the cache.
Helps bad PHP -> JavaScript abuse like jQuery
CCBUG: 149723
M +1 -1 kio/kio/http_slave_defaults.h
M +105 -148 kioslave/http/http.cpp
M +3 -4 kioslave/http/http.h
--- trunk/KDE/kdelibs/kio/kio/http_slave_defaults.h #725637:725638
@@ -28,7 +28,7 @@
#define DEFAULT_CACHE_EXPIRE 3*60 // 3 MINS
#define DEFAULT_CLEAN_CACHE_INTERVAL 30*60 // 30 MINS
#define DEFAULT_CACHE_CONTROL KIO::CC_Refresh // Verify with remote
-#define CACHE_REVISION "8\n" // Cache version
+#define CACHE_REVISION "9\n" // Cache version
// DEFAULT USER AGENT KEY - ENABLES OS NAME
#define DEFAULT_USER_AGENT_KEYS "o" // Show OS
--- trunk/KDE/kdelibs/kioslave/http/http.cpp #725637:725638
@@ -2567,42 +2567,36 @@
setMetaData("HTTP-Headers", m_responseHeaders.join("\n"));
sendMetaData();
}
- m_responseHeaders.clear();
}
-/**
- * This function will read in the return header from the server. It will
- * not read in the body of the return message. It will also not transmit
- * the header to our client as the client doesn't need to know the gory
- * details of HTTP headers.
- */
-bool HTTPProtocol::readHeader()
-{
-try_again:
- kDebug(7113);
+bool HTTPProtocol::readHeaderFromCache() {
+ m_responseHeaders.clear();
- // Check
- if (m_request.bCachedRead)
- {
- m_responseHeaders << QLatin1String("HTTP-CACHE");
- forwardHttpResponseHeader();
+ // Read header from cache...
+ char buffer[4097];
+ if (!gzgets(m_request.fcache, buffer, 4096) )
+ {
+ // Error, delete cache entry
+ kDebug(7113) << "Could not access cache to obtain mimetype!";
+ error( ERR_CONNECTION_BROKEN, m_state.hostname );
+ return false;
+ }
- // Read header from cache...
- char buffer[4097];
- if (!gzgets(m_request.fcache, buffer, 4096) )
- {
+ m_strMimeType = QString::fromUtf8( buffer).trimmed();
+
+ kDebug(7113) << "cached data mimetype: " << m_strMimeType;
+
+ // read http-headers, first the response code
+ if (!gzgets(m_request.fcache, buffer, 4096) )
+ {
// Error, delete cache entry
- kDebug(7113) << "Could not access cache to obtain mimetype!";
+ kDebug(7113) << "Could not access cached data! ";
error( ERR_CONNECTION_BROKEN, m_state.hostname );
return false;
- }
-
- m_strMimeType = QString::fromUtf8( buffer).trimmed();
-
- kDebug(7113) << "cached data mimetype: " << m_strMimeType;
-
- // read optional http-headers
- while(true) {
+ }
+ m_responseHeaders << buffer;
+ // then the headers
+ while(true) {
if (!gzgets(m_request.fcache, buffer, 4096) )
{
// Error, delete cache entry
@@ -2610,41 +2604,53 @@
error( ERR_CONNECTION_BROKEN, m_state.hostname );
return false;
}
+ m_responseHeaders << buffer;
QString header = QString::fromUtf8( buffer).trimmed().toLower();
if (header.isEmpty()) break;
- if (header.startsWith("content-type-charset: ")) {
- QString value = header.mid(22);
- m_request.strCharset = value;
- setMetaData("charset", value);
+ if (header.startsWith("content-type: ")) {
+ int pos = header.indexOf("charset=");
+ if (pos != -1) {
+ QString value = header.mid(pos+8);
+ m_request.strCharset = value;
+ setMetaData("charset", value);
+ }
} else
if (header.startsWith("content-language: ")) {
QString value = header.mid(18);
- m_request.strLanguage = value;
setMetaData("content-language", value);
} else
- if (header.startsWith("content-disposition-type: ")) {
- QString value = header.mid(26);
- m_request.strDisposition = value;
- setMetaData("content-disposition-type", value);
- } else
- if (header.startsWith("content-disposition-filename: ")) {
- QString value = header.mid(30);
- m_request.strFilename = value;
- setMetaData("content-disposition-filename", value);
+ if (header.startsWith("content-disposition: ")) {
+ parseContentDisposition(header.mid(21));
}
- }
+ }
+ forwardHttpResponseHeader();
- if (!m_request.lastModified.isEmpty())
- setMetaData("modified", m_request.lastModified);
- QString tmp;
- tmp.setNum(m_request.expireDate);
- setMetaData("expire-date", tmp);
- tmp.setNum(m_request.creationDate);
- setMetaData("cache-creation-date", tmp);
- mimeType(m_strMimeType);
- return true;
- }
+ if (!m_request.lastModified.isEmpty())
+ setMetaData("modified", m_request.lastModified);
+ QString tmp;
+ tmp.setNum(m_request.expireDate);
+ setMetaData("expire-date", tmp);
+ tmp.setNum(m_request.creationDate);
+ setMetaData("cache-creation-date", tmp);
+ mimeType(m_strMimeType);
+ return true;
+}
+/**
+ * This function will read in the return header from the server. It will
+ * not read in the body of the return message. It will also not transmit
+ * the header to our client as the client doesn't need to know the gory
+ * details of HTTP headers.
+ */
+bool HTTPProtocol::readHeader()
+{
+try_again:
+ kDebug(7113);
+
+ // Check
+ if (m_request.bCachedRead)
+ return readHeaderFromCache();
+
QByteArray locationStr; // In case we get a redirect.
QByteArray cookieStr; // In case we get a cookie.
@@ -2663,6 +2669,7 @@
m_request.etag.clear();
m_request.lastModified.clear();
m_request.strCharset.clear();
+ m_responseHeaders.clear();
time_t dateHeader = 0;
time_t expireDate = 0; // 0 = no info, 1 = already expired, > 1 = actual date
@@ -3047,6 +3054,7 @@
{
mediaValue = mediaValue.toLower();
m_request.strCharset = mediaValue;
+ setMetaData("charset", mediaValue);
}
else
{
@@ -3150,68 +3158,11 @@
}
// Refer to RFC 2616 sec 15.5/19.5.1 and RFC 2183
else if(strncasecmp(buf, "Content-Disposition:", 20) == 0) {
- char* dispositionBuf = trimLead(buf + 20);
- while ( *dispositionBuf )
- {
- if ( strncasecmp( dispositionBuf, "filename", 8 ) == 0 )
- {
- dispositionBuf += 8;
-
- while ( *dispositionBuf == ' ' || *dispositionBuf == '=' )
- dispositionBuf++;
-
- char* bufStart = dispositionBuf;
-
- while ( *dispositionBuf && *dispositionBuf != ';' )
- dispositionBuf++;
-
- if ( dispositionBuf > bufStart )
- {
- // Skip any leading quotes...
- while ( *bufStart == '"' )
- bufStart++;
-
- // Skip any trailing quotes as well as white spaces...
- while ( *(dispositionBuf-1) == ' ' || *(dispositionBuf-1) == '"')
- dispositionBuf--;
-
- if ( dispositionBuf > bufStart )
- m_request.strFilename = QString::fromLatin1( bufStart, \
dispositionBuf-bufStart );
-
- break;
- }
- }
- else
- {
- char *bufStart = dispositionBuf;
-
- while ( *dispositionBuf && *dispositionBuf != ';' )
- dispositionBuf++;
-
- if ( dispositionBuf > bufStart )
- m_request.strDisposition = QString::fromLatin1( bufStart, \
dispositionBuf-bufStart ).trimmed();
-
- while ( *dispositionBuf == ';' || *dispositionBuf == ' ' )
- dispositionBuf++;
- }
- }
-
- // Content-Dispostion is not allowed to dictate directory
- // path, thus we extract the filename only.
- if ( !m_request.strFilename.isEmpty() )
- {
- int pos = m_request.strFilename.lastIndexOf( '/' );
-
- if( pos > -1 )
- m_request.strFilename = m_request.strFilename.mid(pos+1);
-
- kDebug(7113) << "Content-Disposition: filename=" << m_request.strFilename;
- }
+ parseContentDisposition(QString::fromLatin1(trimLead(buf+20)));
}
else if(strncasecmp(buf, "Content-Language:", 17) == 0) {
QString language = QString::fromLatin1(trimLead(buf+17)).trimmed();
if (!language.isEmpty()) {
- m_request.strLanguage = language;
setMetaData("content-language", language);
}
}
@@ -3341,7 +3292,9 @@
// Send the current response before processing starts or it
// might never get sent...
- forwardHttpResponseHeader();
+ // Except if this is just a validation, then the cached request sends them
+ if (!cacheValidated)
+ forwardHttpResponseHeader();
// Now process the HTTP/1.1 upgrade
QStringList::Iterator opt = upgradeOffers.begin();
@@ -3364,8 +3317,6 @@
}
}
- setMetaData("charset", m_request.strCharset);
-
// If we do not support the requested authentication method...
if ( (m_responseCode == 401 && Authentication == AUTH_None) ||
(m_responseCode == 407 && ProxyAuthentication == AUTH_None) )
@@ -3670,19 +3621,6 @@
m_strMimeType = QString::fromLatin1("video/x-ms-wmv");
}
- if( !m_request.strDisposition.isEmpty() )
- {
- kDebug(7113) << "Setting Content-Disposition type to: "
- << m_request.strDisposition;
- setMetaData("content-disposition-type", m_request.strDisposition);
- }
- if( !m_request.strFilename.isEmpty() )
- {
- kDebug(7113) << "Setting Content-Disposition filename to: "
- << m_request.strFilename;
- setMetaData("content-disposition-filename", m_request.strFilename);
- }
-
if (!m_request.lastModified.isEmpty())
setMetaData("modified", m_request.lastModified);
@@ -3734,7 +3672,43 @@
return true;
}
+void HTTPProtocol::parseContentDisposition(const QString &disposition)
+{
+ QString strDisposition;
+ QString strFilename;
+ QStringList parts = disposition.split(';');
+
+ bool first = true;
+ foreach(QString part, parts) {
+ part = part.trimmed();
+ if (first) {
+ strDisposition = part;
+ first = false;
+ } else
+ if (part.startsWith("filename")) {
+ int i = part.indexOf('=');
+ if (i == -1) break;
+ strFilename = part.mid(i);
+ }
+ }
+
+ // Content-Dispostion is not allowed to dictate directory
+ // path, thus we extract the filename only.
+ if ( !strFilename.isEmpty() )
+ {
+ int pos = strFilename.lastIndexOf( '/' );
+
+ if( pos > -1 )
+ strFilename = strFilename.mid(pos+1);
+
+ kDebug(7113) << "Content-Disposition: filename=" << strFilename;
+ }
+ setMetaData("content-disposition-type", strDisposition);
+ if (!strFilename.isEmpty())
+ setMetaData("content-disposition-filename", strFilename);
+}
+
void HTTPProtocol::addEncoding(const QString &_encoding, QStringList &encs)
{
QString encoding = _encoding.trimmed().toLower();
@@ -4768,28 +4742,11 @@
gzputs(m_request.fcache, mimetype.toLatin1()); // Mimetype
gzputc(m_request.fcache, '\n');
- if (!m_request.strCharset.isEmpty()) {
- gzputs(m_request.fcache, "content-type-charset: ");
- gzputs(m_request.fcache, m_request.strCharset.toLatin1()); // Charset
- gzputc(m_request.fcache, '\n');
- }
- if (!m_request.strLanguage.isEmpty()) {
- gzputs(m_request.fcache, "content-language: ");
- gzputs(m_request.fcache, m_request.strLanguage.toLatin1()); // \
Content-language
- gzputc(m_request.fcache, '\n');
- }
- if (!m_request.strDisposition.isEmpty()) {
- gzputs(m_request.fcache, "content-disposition-type: ");
- gzputs(m_request.fcache, m_request.strDisposition.toLatin1()); // \
Content-Disposition
- gzputc(m_request.fcache, '\n');
- }
- if (!m_request.strFilename.isEmpty()) {
- gzputs(m_request.fcache, "content-disposition-filename: ");
- gzputs(m_request.fcache, m_request.strFilename.toLatin1()); // \
Content-Disposition: filename
- gzputc(m_request.fcache, '\n');
- }
+ gzputs(m_request.fcache, m_responseHeaders.join("\n").toLatin1());
gzputc(m_request.fcache, '\n');
+ gzputc(m_request.fcache, '\n');
+
return;
}
// The above code should be kept in sync
--- trunk/KDE/kdelibs/kioslave/http/http.h #725637:725638
@@ -164,10 +164,7 @@
long bytesCached;
time_t expireDate; // Date when the cache entry will expire
time_t creationDate; // Date when the cache entry was created
- QString strCharset; // Charset
- QString strLanguage; // Language
- QString strDisposition;
- QString strFilename;
+ QString strCharset;
// Cookie flags
enum { CookiesAuto, CookiesManual, CookiesNone } cookieMode;
@@ -299,6 +296,8 @@
void forwardHttpResponseHeader();
bool readHeader();
+ bool readHeaderFromCache();
+ void parseContentDisposition(const QString &disposition);
bool sendBody();
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic