add setStatusCode request api member
Stefan Bund [Tue, 21 Dec 2010 00:19:00 +0000 (01:19 +0100)]
Publisher.cc
Publisher.hh
PythonPublisher.cc

index cd5caf3..30a6789 100644 (file)
@@ -51,6 +51,7 @@ namespace detail {
 
         using QNetworkReply::setHeader;
         using QNetworkReply::setRawHeader;
+        using QNetworkReply::setAttribute;
 
         void clearResponse();
         QByteArray postData() const;
@@ -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); }
@@ -254,6 +259,11 @@ prefix_ void pykit::Request::setHeader(std::string const & header, std::string c
     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
 {
index 72862d2..6cd3287 100644 (file)
@@ -32,6 +32,7 @@ namespace pykit {
         void setContentType(std::string const & contentType);
         void setLocation(std::string const & location);
         void setHeader(std::string const & header, std::string const & value);
+        void setStatusCode(int code);
 
         QUrl url() const;
         QByteArray postData() const;
index 8ab72be..fc29b6f 100644 (file)
@@ -424,6 +424,7 @@ BOOST_PYTHON_MODULE(_pykit)
         .def("setContentType", &pykit::Request::setContentType)
         .def("setLocation", &pykit::Request::setLocation)
         .def("setRawHeader", &pykit::Request::setHeader)
+        .def("setStatusCode", &pykit::Request::setStatusCode)
         .def("url", &pykit::Request::url)
         .def("postData", &pykit::Request::postData)
         .def("operation", &pykit::Request::operation)