Bug 60898 - http slave doesn't seem to notice errors
Summary: http slave doesn't seem to notice errors
Status: RESOLVED FIXED
Alias: None
Product: kio
Classification: Frameworks and Libraries
Component: http (show other bugs)
Version: unspecified
Platform: openSUSE Linux
: NOR normal
Target Milestone: ---
Assignee: Unassigned bugs mailing-list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-07-08 01:33 UTC by Leif Huhn
Modified: 2003-07-09 12:51 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Leif Huhn 2003-07-08 01:33:29 UTC
Version:            (using KDE KDE 3.1.2)
Installed from:    SuSE RPMs
OS:          Linux

I'm using the HTTP slave, and the webserver gives me a 403 Permission denied in the logs.  The application doesn't care or notice and acts as if it actually saved my file.

I tried this in Kate pointing it to http://mywebserver/~leif/story.sav and in the apache logs I get:

64.171.250.148 - - [07/Jul/2003:16:16:22 -0700] "PUT /~leif/story.sav HTTP/1.1" 403 299

But Kate doesn't notice something bad happened.

Also, if I run:

KURL url("http://mywebserver/~leif/story.sav");
KURL temporaryLocalFilename;
temporaryLocalFilename.setPath("/tmp/notalocalfile"); // This is a zero byte file BTW
kdDebug() << KIO::NetAccess::copy(temporaryLocalFilename, url) << endl;
kdDebug() << KIO::NetAccess::lastErrorString() << endl;

I get the results:

programname: true
programname:

This problem also seems to apply to "405 Method not allowed"  I have not checked other error conditions.
Comment 1 Waldo Bastian 2003-07-09 12:51:58 UTC
Subject: kdelibs/kioslave/http

CVS commit by waba: 

CCMAIL: 60898-done@bugs.kde.org
Perform error checking when uploading files. (BR60898)
(Requires testing before backporting!)


  M +76 -1     http.cc   1.584
  M +2 -0      http.h   1.156


--- kdelibs/kioslave/http/http.cc  #1.583:1.584
@@ -1164,5 +1164,18 @@ void HTTPProtocol::put( const KURL &url,
   m_request.doProxy = m_bUseProxy;
 
-  retrieveHeader( true );
+  retrieveHeader( false );
+
+  kdDebug(7113) << "(" << m_pid << ") HTTPProtocol::put error = " << m_bError << endl;
+  if (m_bError)
+    return;
+
+  kdDebug(7113) << "(" << m_pid << ") HTTPProtocol::put responseCode = " << m_responseCode << endl;
+
+  httpClose(false); // Always close connection.
+
+  if ( (m_responseCode >= 200) && (m_responseCode < 300) )
+    finished();
+  else
+    httpError();
 }
 
@@ -1552,4 +1565,66 @@ QString HTTPProtocol::davError( int code
 
   return errorString;
+}
+
+void HTTPProtocol::httpError()
+{
+  QString action, errorString;
+  KIO::Error kError;
+
+  switch ( m_request.method ) {
+    case HTTP_PUT:
+      action = i18n( "upload %1" ).arg(m_request.url.prettyURL());
+      break;
+    default:
+      // this should not happen, this function is for http errors only
+      Q_ASSERT(0);
+  }
+
+  // default error message if the following code fails
+  kError = ERR_INTERNAL;
+  errorString = i18n("An unexpected error (%1) occurred while attempting to %2.")
+                      .arg( m_responseCode ).arg( action );
+
+  switch ( m_responseCode )
+  {
+    case 403:
+    case 405:
+    case 500: // hack: Apache mod_dav returns this instead of 403 (!)
+      // 403 Forbidden
+      // 405 Method Not Allowed
+      kError = ERR_ACCESS_DENIED;
+      errorString = i18n("Access was denied while attempting to %1.").arg( action );
+      break;
+    case 409:
+      // 409 Conflict
+      kError = ERR_ACCESS_DENIED;
+      errorString = i18n("A resource cannot be created at the destination "
+                  "until one or more intermediate collections (directories) "
+                  "have been created.");
+      break;
+    case 423:
+      // 423 Locked
+      kError = ERR_ACCESS_DENIED;
+      errorString = i18n("Unable to %1 because the resource is locked.").arg( action );
+      break;
+    case 502:
+      // 502 Bad Gateway
+      kError = ERR_WRITE_ACCESS_DENIED;
+      errorString = i18n("Unable to %1 because the destination server refuses "
+                         "to accept the file or directory.").arg( action );
+      break;
+    case 507:
+      // 507 Insufficient Storage
+      kError = ERR_DISK_FULL;
+      errorString = i18n("The destination resource does not have sufficient space "
+                         "to record the state of the resource after the execution "
+                         "of this method.");
+      break;
+  }
+
+  // if ( kError != ERR_SLAVE_DEFINED )
+  //errorString += " (" + url + ")";
+
+  error( ERR_SLAVE_DEFINED, errorString );
 }
 

--- kdelibs/kioslave/http/http.h  #1.155:1.156
@@ -244,4 +244,6 @@ public:
   void cacheUpdate( const KURL &url, bool nocache, time_t expireDate);
 
+  void httpError(); // Generate error message based on response code
+
 protected slots:
   void slotData(const QByteArray &);