Bug 267063 - Saving a file with HTTP doesn't follow HTTP 307 redirects
Summary: Saving a file with HTTP doesn't follow HTTP 307 redirects
Status: RESOLVED FIXED
Alias: None
Product: kio
Classification: Frameworks and Libraries
Component: http (show other bugs)
Version: unspecified
Platform: Debian stable Linux
: NOR normal
Target Milestone: ---
Assignee: kdelibs bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-24 16:37 UTC by bert
Modified: 2011-10-25 21:14 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In: 4.7.3


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bert 2011-02-24 16:37:51 UTC
Version:           unspecified (using KDE 4.4.5) 
OS:                Linux

I opened a (password-protected) file https://www.w3.org/... in Kate, edited it and tried to save it. The server returned a 307 "temporary redirect" with location http://edit.w3.org/... Kate didn't understand the redirect and reported "An unexpected error (307) occurred while attempting to upload https://www.w3.org/..."

Saving the file directly to the redirected URL works fine, so KDE handles the PUT correctly, just not the redirect.

I guess this is not a specific to Kate, but a general problem with HTTP in KDE. I noticed the same behavior with HTTP-based calendars in Korganizer.

Reproducible: Always

Steps to Reproduce:
You need a Web server that accepts the PUT request (and probably a password, because few servers allow just anybody to create or change pages...). People with write access to some part of the W3C server (www.w3.org) can try it there. You also need a URL on that server that is redirected with a 307 "temporary redirect" to another URL (on the same server or elsewhere).

Then open the first URL into Kate and press Save. You may be prompted for a password first, but then Kate pops up an error box with the error message quoted above ("An unexpected error (307)...").

Actual Results:  
And error dialog and nothing else. The file was not saved.

Expected Results:  
No error, and a successful save of the file on the remote server.
Comment 1 Milian Wolff 2011-02-28 17:47:50 UTC
kdelibs bug
Comment 2 Dawit Alemayehu 2011-06-08 04:49:50 UTC
Sorry but this is not really a HTTP or kdelibs bug. kate or kwrite or any application for that matter needs to deal with the possiblity of a redirection for such operations. 

Only redirection of a POST operation is handled automatically and even that happens for historical reason. If a server redirects a POST operation, then it is automatically converted into a GET operation (a relatively benign action). However, that is not the case for a PUT operation. If the server redirects a PUT operation, then it is the client's responsiblity to confirm whether that action is desired and put a new request with the redirection url.

To achieve this the client application must connect to the job's redirection signal and store the redirection url. Then if it gets an error message, it needs to redo the request with the newly saved url. Sorry, but there is no way around that.
Comment 3 Christoph Cullmann 2011-06-25 21:16:35 UTC
KParts handles the uploading for us, see save/saveAs in read-write-part.
It must be fixed there or any other kparts part must reimplement that methods.
Comment 4 Christoph Feck 2011-07-24 00:59:44 UTC
Dawit, can you clarify if this can be fixed in kio? It clearly isn't an kdeui bug.
Comment 5 Dawit Alemayehu 2011-07-27 00:30:38 UTC
(In reply to comment #4)
> Dawit, can you clarify if this can be fixed in kio? It clearly isn't an kdeui
> bug.

Not sure, but this needs further investigation based on feedback in comment #3. Please disregard what I stated in comment #2 since it is factually incorrect. Redirection are always handled internally by KIO ; so this could not be the fault of the application. However, to find out what might be causing this issue, we need access to a server where we can reproduce this issue or otherwise provide the debug out from such session.
Comment 6 Dawit Alemayehu 2011-10-23 14:18:55 UTC
I know why this happens now. It is a kio_http bug caused by the fact that its PUT handling does not account for redirection. Will be fixed soon.
Comment 7 Dawit Alemayehu 2011-10-25 21:14:06 UTC
Git commit 3f697e30d28d311015484a01e67e8bb95477e7fa by Dawit Alemayehu.
Committed on 22/10/2011 at 02:07.
Pushed by adawit into branch 'KDE/4.7'.

Make sure both DELETE and PUT requests properly handle redirection requests
to address the issue reported in bug# 267063. In the process of addressing the
afformentioned bug the following related changes and cleanups were performed:

  - Removed the check for HTTP_POST on redirection so that kio_http behaves
    exactly like Firefox and Chromium except for HEAD requests. Converting
    HEAD requests to GET makes no sense.

  - Changed both ::del and ::put to leave the query component of the request
    URL alone except for WebDAV requests. Not sure why it is removed for DAV
    requests either.

  - Changed ::del to properly handles any message body returned by the server.

  - Renamed sendHttpPutError to sendHttpError and converted it to handle HTTP
    response code errors for all HTTP methods, not just PUT.

  - Changed proceedUntilResponseContent to use the new sendHttpError function
    to send error to the client.

  - Converted both ::del and ::put to use proceedUntilResponseContent since it
    now correctly handles errors returned by the server.

BUG: 267063
FIXED-IN: 4.7.3

M  +172  -102  kioslave/http/http.cpp
M  +3    -2    kioslave/http/http.h

http://commits.kde.org/kdelibs/3f697e30d28d311015484a01e67e8bb95477e7fa