Hi all,
I have to add support for a custom scheme to QWebView so that a javascript call to XMLHttpRequest([custom scheme URL]) returns the HTTP status code, even if the URL doesn’t have an HTTP scheme.
In a similar way as described in “Adding New Protocols” http://doc.qt.digia.com/qq/32/qq32-webkit-protocols.html, I subclass QNetworkAccessManager and reimplement its createRequest() function to check for URLs with my custom scheme.
I also subclass QNetworkReply to reimplement bytesAvailable() and readData().
When the content at the custom URL is available I set the headers
setAttribute(QNetworkRequest::HttpStatusCodeAttribute,QVariant(200));
setHeader(QNetworkRequest::ContentTypeHeader, QVariant("text/html; charset=UTF-8"));
setHeader(QNetworkRequest::ContentLengthHeader, QVariant((uint)new_content_size));
and emit readRead and finished
QTimer::singleShot( 0, this, SIGNAL(readyRead()) );
QTimer::singleShot( 0, this, SIGNAL(finished()) );
but XMLHttpRequest dosn’t return the HTTP status code I set with
setAttribute(QNetworkRequest::HttpStatusCodeAttribute,QVariant(200));
I suspect this happens because in QNetworkReplyHandler.cpp (void QNetworkReplyHandler::sendResponseIfNeeded()) the URL is tested against “url.protocolInHTTPFamily()” before setting the HTTP status code in the response. Is my understanding correct?
Is there a way to force my Reply to return the HTTP status code, when the URL scheme is not actually HTTP?
Thanks
↧