Holger Hans Peter Freyther <zecke@selfish.org>
[WebKit-https.git] / WebCore / platform / network / qt / QNetworkReplyHandler.cpp
index a4cb73f..5e3d943 100644 (file)
@@ -29,6 +29,7 @@
 #include "ResourceHandleInternal.h"
 #include "ResourceResponse.h"
 #include "ResourceRequest.h"
+#include <QDateTime>
 #include <QFile>
 #include <QNetworkReply>
 #include <QNetworkCookie>
@@ -132,6 +133,7 @@ QNetworkReplyHandler::QNetworkReplyHandler(ResourceHandle *handle)
     , m_reply(0)
     , m_redirected(false)
     , m_responseSent(false)
+    , m_startTime(0)
 {
     const ResourceRequest &r = m_resourceHandle->request();
 
@@ -221,12 +223,15 @@ void QNetworkReplyHandler::sendResponseIfNeeded()
     }
 
     KURL url(m_reply->url());
-    String contentDisposition = QString::fromAscii(m_reply->rawHeader("Content-Disposition"));
+    String suggestedFilename = filenameFromHTTPContentDisposition(QString::fromAscii(m_reply->rawHeader("Content-Disposition")));
+
+    if (suggestedFilename.isEmpty())
+        suggestedFilename = url.lastPathComponent();
 
     ResourceResponse response(url, mimeType,
                               m_reply->header(QNetworkRequest::ContentLengthHeader).toLongLong(),
                               encoding,
-                              filenameFromHTTPContentDisposition(contentDisposition));
+                              suggestedFilename);
 
     const bool isLocalFileReply = (m_reply->url().scheme() == QLatin1String("file"));
     int statusCode = m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
@@ -249,6 +254,9 @@ void QNetworkReplyHandler::sendResponseIfNeeded()
         response.setHTTPHeaderField(QString::fromAscii(headerName), QString::fromAscii(m_reply->rawHeader(headerName)));
     }
 
+    if (isLocalFileReply)
+        response.setExpirationDate(m_startTime);
+
     QUrl redirection = m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
     if (redirection.isValid()) {
         QUrl newUrl = m_reply->url().resolved(redirection);
@@ -304,6 +312,8 @@ void QNetworkReplyHandler::start()
         && (!url.toLocalFile().isEmpty() || url.scheme() == QLatin1String("data")))
         m_method = QNetworkAccessManager::GetOperation;
 
+    m_startTime = QDateTime::currentDateTime().toTime_t();
+
     switch (m_method) {
         case QNetworkAccessManager::GetOperation:
             m_reply = manager->get(m_request);