typo fix
[pykit.git] / Publisher.cc
index 23eb5bf..30a6789 100644 (file)
@@ -50,6 +50,8 @@ namespace detail {
         virtual void abort();
 
         using QNetworkReply::setHeader;
+        using QNetworkReply::setRawHeader;
+        using QNetworkReply::setAttribute;
 
         void clearResponse();
         QByteArray postData() const;
@@ -98,7 +100,6 @@ InternalServerReply(QNetworkAccessManager::Operation operation,
 prefix_ void pykit::detail::InternalServerReply::bufferPostData()
 {
     QVariant cl (request().header(QNetworkRequest::ContentLengthHeader));
-    std::cerr << "postdata contentlength: " << (cl.isValid() ? cl.toString().toStdString() : "invalid") << "\n";
     connect(postDevice_, SIGNAL(readyRead()), this, SLOT(postDataReadable()));
     connect(postDevice_, SIGNAL(readChannelFinished()), this, SLOT(postDataComplete()));
     postData_.open(WriteOnly);
@@ -156,7 +157,6 @@ prefix_ void pykit::detail::InternalServerReply::processRequest()
 prefix_ void pykit::detail::InternalServerReply::complete()
 {
     emit readyRead();
-    emit readChannelFinished();
     emit finished();
 }
 
@@ -201,7 +201,12 @@ prefix_ bool pykit::detail::InternalServerReply::waitForReadyRead(int msecs)
 { return buffer_.waitForReadyRead(msecs); }
 
 prefix_ qint64 pykit::detail::InternalServerReply::readData(char * data, qint64 maxSize)
-{ return buffer_.read(data,maxSize); }
+{
+    qint64 n (buffer_.read(data,maxSize));
+    if (buffer_.atEnd())
+        emit readChannelFinished();
+    return n;
+}
 
 prefix_ qint64 pykit::detail::InternalServerReply::writeData(char const * data, qint64 maxSize)
 { return buffer_.write(data,maxSize); }
@@ -249,6 +254,16 @@ prefix_ void pykit::Request::setLocation(std::string const & location)
     reply_.setHeader(QNetworkRequest::LocationHeader, QVariant(location.c_str()));
 }
 
+prefix_ void pykit::Request::setHeader(std::string const & header, std::string const & value)
+{
+    reply_.setRawHeader(header.c_str(), value.c_str());
+}
+
+prefix_ void pykit::Request::setStatusCode(int code)
+{
+    reply_.setAttribute(QNetworkRequest::HttpStatusCodeAttribute, code);
+}
+
 prefix_ QUrl pykit::Request::url()
     const
 {
@@ -298,9 +313,8 @@ pykit::InternalNetworkAccessManager::createRequest(Operation operation,
                                                         QNetworkRequest const & request,
                                                         QIODevice * device)
 {
-    if (request.url().scheme() != "srv")
+    if (request.url().host() != "pykit")
         return QNetworkAccessManager::createRequest(operation, request, device);
-
     return new detail::InternalServerReply(operation, request, device, publisher_);
 }