[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kfm-devel
Subject:    PATCH: xmlhttprequest cannot handle cached documents
From:       Dawit Alemayehu <adwa () cox ! net>
Date:       2005-08-07 17:54:02
Message-ID: 200508071354.03057.adwa () cox ! net
[Download RAW message or body]

The attached patch 

- Fixesbug# 110272 by converting a 304 (Not Modified) HTTP response in 
XMLHttpRequest to a 200 (OK) response to make KHTML conform to IE's and 
Mozilla's behavior. 

- Factors out the code that parses the HTTP response for the status info into 
a single function to avoid code duplication.

-- 
Regards,	
Dawit A.

["110272.diff" (text/x-diff)]

Index: xmlhttprequest.cpp
===================================================================
--- xmlhttprequest.cpp	(revision 443873)
+++ xmlhttprequest.cpp	(working copy)
@@ -439,14 +439,14 @@
   return String(responseHeaders.mid(headerLinePos + matchLength, endOfLine - \
(headerLinePos + matchLength)).stripWhiteSpace());  }
 
-Value XMLHttpRequest::getStatus() const
+static Value httpStatus(const QString& response, bool textStatus = false)
 {
-  if (responseHeaders.isEmpty()) {
+  if (response.isEmpty()) {
     return Undefined();
   }
 
-  int endOfLine = responseHeaders.find("\n");
-  QString firstLine = endOfLine == -1 ? responseHeaders : \
responseHeaders.left(endOfLine); +  int endOfLine = response.find("\n");
+  QString firstLine = (endOfLine == -1) ? response : response.left(endOfLine);
   int codeStart = firstLine.find(" ");
   int codeEnd = firstLine.find(" ", codeStart + 1);
 
@@ -454,6 +454,11 @@
     return Undefined();
   }
 
+  if (textStatus) {
+    QString statusText = firstLine.mid(codeEnd + 1, endOfLine - (codeEnd + \
1)).stripWhiteSpace(); +    return String(statusText);
+  }
+
   QString number = firstLine.mid(codeStart + 1, codeEnd - (codeStart + 1));
 
   bool ok = false;
@@ -465,24 +470,14 @@
   return Number(code);
 }
 
+Value XMLHttpRequest::getStatus() const
+{
+  return httpStatus(responseHeaders);
+}
+
 Value XMLHttpRequest::getStatusText() const
 {
-  if (responseHeaders.isEmpty()) {
-    return Undefined();
-  }
-
-  int endOfLine = responseHeaders.find("\n");
-  QString firstLine = endOfLine == -1 ? responseHeaders : \
                responseHeaders.left(endOfLine);
-  int codeStart = firstLine.find(" ");
-  int codeEnd = firstLine.find(" ", codeStart + 1);
-
-  if (codeStart == -1 || codeEnd == -1) {
-    return Undefined();
-  }
-
-  QString statusText = firstLine.mid(codeEnd + 1, endOfLine - (codeEnd + \
                1)).stripWhiteSpace();
-
-  return String(statusText);
+  return httpStatus(responseHeaders, true);
 }
 
 void XMLHttpRequest::processSyncLoadResults(const QByteArray &data, const KURL \
&finalURL, const QString &headers) @@ -544,6 +539,17 @@
 {
   if (state < Loaded ) {
     responseHeaders = job->queryMetaData("HTTP-Headers");
+
+    // NOTE: Replace a 304 response with a 200! Both IE and Mozilla do this.
+    // Problem first reported through bug# 110272.
+    int codeStart = responseHeaders.find("304");
+    if ( codeStart != -1) {
+      int codeEnd = responseHeaders.find("\n", codeStart+3);
+      if (codeEnd != -1)
+        responseHeaders.replace(codeStart, (codeEnd-codeStart), "200 OK");
+      // qDebug("Response Header: %s", responseHeaders.latin1());
+    }
+
     changeState(Loaded);
   }
 



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic