This forum has been archived. All content is frozen. Please use KDE Discuss instead.

KIO::put doesn't read reponse body (for http)?

Tags: None
(comma "," separated)
timotheeg
Registered Member
Posts
3
Karma
0
OS
Hi all,

I'm doing my first KDE project, which is a KIPI plugin to export pics to a online hosting service my company provides (I'm a total C++ newbie, please bear with me :p).

We have a rest API for the online service, and I need to send image files via put requests to a specific url. I'm using KIO::put for that, I'm able to use the "dataReq" and "result" signals on the job, but for some reason the "data" signal is not emitted.

Some of the other rest calls do work as expected using KIO::get. For example, I get the following debug output:

Code: Select all
kio_http(23078) HTTPProtocol::readResponseHeader: ============ Received Status Response:
kio_http(23078) HTTPProtocol::readResponseHeader: "HTTP/1.1 200 OK
"
kio_http(23078)/kio_http_debug HTTPProtocol::readResponseHeader:  -- full response: "HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Date: Fri, 09 Oct 2009 07:56:48 GMT
Server: Noelios-Restlet-Engine/1.0.5
Content-Type: application/xml
Transfer-Encoding: chunked

"
kio_http(23078)/kio_http_debug HTTPProtocol::readResponseHeader: Content-type:  "application/xml"
kio_http(23078)/kio_http_debug HTTPProtocol::readResponseHeader: Emitting mimetype  "application/xml"
kio_http(23078)/kio_http_debug HTTPProtocol::readResponseHeader: Cache, adding "http://shentonstaging.muvee.com:8080/shenton/services/rest/user/timothee%40muvee.com/albums"
kio_http(23078)/kio_http_debug HTTPProtocol::proceedUntilResponseHeader: Previous Response: 0
kio_http(23078)/kio_http_debug HTTPProtocol::proceedUntilResponseHeader: Current Response: 200
kio_http(23078)/kio_http_debug HTTPProtocol::readBody: retrieve data. "-1" left.
kio_http(23078)/kio_http_debug HTTPProtocol::readChunked: Chunk size =  7444  bytes
kio_http(23078)/kio_http_debug HTTPProtocol::readChunked: Chunk size =  0  bytes
kio_http(23078)/kio_http_debug HTTPProtocol::readBody: EOD received! Left =  "0"
kio_http(23078)/kio_http_debug HTTPProtocol::httpClose: keepAlive = true
kio_http(23078)/kio_http_debug HTTPProtocol::httpClose: keep alive ( 60 )


Notice how there is a "readBody" action in that case, and the signal "data" is emitted. With KIO::put, I only get:

Code: Select all
kio_http(23078) HTTPProtocol::readResponseHeader: ============ Received Status Response:
kio_http(23078) HTTPProtocol::readResponseHeader: "HTTP/1.1 200 OK
"
kio_http(23078)/kio_http_debug HTTPProtocol::readResponseHeader:  -- full response: "HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Date: Fri, 09 Oct 2009 07:56:51 GMT
Server: Noelios-Restlet-Engine/1.0.5
Content-Type: application/xml
Transfer-Encoding: chunked

"
kio_http(23078)/kio_http_debug HTTPProtocol::readResponseHeader: Content-type:  "application/xml"
kio_http(23078)/kio_http_debug HTTPProtocol::readResponseHeader: Emitting mimetype  "application/xml"
kio_http(23078)/kio_http_debug HTTPProtocol::proceedUntilResponseHeader: Previous Response: 0
kio_http(23078)/kio_http_debug HTTPProtocol::proceedUntilResponseHeader: Current Response: 200
kio_http(23078)/kio_http_debug HTTPProtocol::put: error =  false
kio_http(23078)/kio_http_debug HTTPProtocol::put: responseCode =  200
kio_http(23078)/kio_http_debug HTTPProtocol::httpClose: keepAlive = false
kio_http(23078)/kio_http_debug HTTPProtocol::httpCloseConnection:


In that case, there is no "readBody", even though I know there is data and the mimetype signal is being emmited.

Here is the code I use:
Code: Select all
   // ... snipped code above ...

    KIO::TransferJob* job = KIO::put(QString("%1%2").arg(m_apiURL).arg(requestPath), -1, KIO::HideProgressInfo);
   
    // ok we have all the data, add all the metadata to the job
    job->addMetaData("UserAgent", m_userAgent);
    job->addMetaData("content-type", QString("Content-Type: %1").arg( mime ));
    job->addMetaData("customHTTPHeader",
            QString("Content-MD5: %1\r\nDate: %2\r\nAuthorization: Shenton: %3 : %4")
                .arg(md5)
                .arg(date)
                .arg(m_apiKey)
                .arg(authorizationEncoded)
    );
       
    connect(job, SIGNAL(data(KIO::Job*, const QByteArray&)),
            this, SLOT(data(KIO::Job*, const QByteArray&)));

    connect(job, SIGNAL(dataReq(KIO::Job*, QByteArray&)),
            this, SLOT(slotAddPhotoDataRequest(KIO::Job*, QByteArray&)));

    connect(job, SIGNAL(result(KJob*)),
            this, SLOT(slotAddPhotoResult(KJob*)));

   // ... snipped code below ...



Is that expected behavior for KIO::put? How can I fix this?

Ho, additionnaly, I have another problem with KIO::put, if the http url, where I want to put the file, contains a query string, it is dropped in the request. Is that expected too?

For example, I might do:
Code: Select all
    KIO::TransferJob* job = KIO::put("http://somesite.com/path?param=value", -1, KIO::HideProgressInfo);


but the kio http debug shows:
Code: Select all
kio_http(23002) HTTPProtocol::sendQuery: "PUT /path HTTP/1.1"
kio_http(23002) HTTPProtocol::sendQuery: "Host: somesite.com"


Is there any way to fix that too?

Tim.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
As this is a issue with the KIO library ( which is part of KDELibs ) you may be able to find better help on the #kde-devel channel on Freenode or on the kde-devel@kde.org mailing list.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
timotheeg
Registered Member
Posts
3
Karma
0
OS
Thanks bcooksley, I will send this message on the kde-devel mailing list.

In case someone else comes to these forums, I forgot to mention that I use kde 4.3.1 on gentoo.

Tim.


Bookmarks



Who is online

Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]