Skip to content

Commit

Permalink
Added setting right Content-Length.
Browse files Browse the repository at this point in the history
  • Loading branch information
shaitan committed Jun 20, 2013
1 parent 821a3ce commit 2ae3b24
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Build-Depends: debhelper (>= 7.0.50~),
libboost-system-dev,
libboost-thread-dev,
libfastcgi-daemon2-dev,
elliptics-dev (>= 2.24),
elliptics-dev (>= 2.24.9.1),
libmsgpack-dev
Standards-Version: 3.8.0
Homepage: http://github.com/reverbrain/historydb/
Expand Down
13 changes: 11 additions & 2 deletions src/fastcgi/historydb-fastcgi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,27 +116,28 @@ namespace history { namespace fcgi {
void handler::handle_root(fastcgi::Request* req, fastcgi::HandlerContext*)
{
m_logger->debug("Handle root request\n");
req->setHeader("Content-Length", "0");
req->setStatus(200);
}

void handler::handle_wrong_uri(fastcgi::Request* req, fastcgi::HandlerContext*)
{
m_logger->error("Handle request for unknown/unexpected uri:%s\n", req->getURI().c_str());
req->setHeader("Content-Length", "0");
req->setStatus(404); // Sets 404 status for respone - wrong uri code
}

void handler::handle_add_log(fastcgi::Request* req, fastcgi::HandlerContext*)
{
m_logger->debug("Handle add log request\n");
req->setHeader("Content-Length", "0");

if (!req->hasArg("user") || !req->hasArg("data") || (!req->hasArg("time") && !req->hasArg("key"))) {
m_logger->error("Required parameter 'data' or 'user' or 'time' is missing\n");
req->setStatus(400);
return;
}

fastcgi::RequestStream stream(req);

auto user = req->getArg("user");
auto data = req->getArg("data");

Expand Down Expand Up @@ -181,6 +182,7 @@ namespace history { namespace fcgi {
void handler::handle_add_activity(fastcgi::Request* req, fastcgi::HandlerContext*)
{
m_logger->debug("Handle add activity request\n");
req->setHeader("Content-Length", "0");

if(!req->hasArg("user")) {
m_logger->error("Required parameter 'user' is missing\n");
Expand Down Expand Up @@ -251,6 +253,7 @@ namespace history { namespace fcgi {
}
else { // if key and time aren't among the parameters
m_logger->error("Key and time are missing\n");
req->setHeader("Content-Length", "0");
req->setStatus(400);
return;
}
Expand All @@ -274,6 +277,7 @@ namespace history { namespace fcgi {
auto json = buffer.GetString();

m_logger->debug("Result json: %s\n", json);
req->setHeader("Content-Length", boost::lexical_cast<std::string>(buffer.Size()));

stream << json; // write result json to fastcgi stream
}
Expand All @@ -285,6 +289,7 @@ namespace history { namespace fcgi {

if (!req->hasArg("user") || !req->hasArg("begin_time") || !req->hasArg("end_time")) { // checks required parameters
m_logger->error("Required parameter 'user' or 'begin_time' or 'end_time' is missing\n");
req->setHeader("Content-Length", "0");
req->setStatus(400);
return;
}
Expand Down Expand Up @@ -316,7 +321,11 @@ namespace history { namespace fcgi {

m_logger->debug("Result json: %s\n", json);

req->setHeader("Content-Length", boost::lexical_cast<std::string>(buffer.Size()));

stream << json; // writes result json to fastcgi stream

req->setStatus(200);
}

FCGIDAEMON_REGISTER_FACTORIES_BEGIN()
Expand Down
2 changes: 1 addition & 1 deletion src/lib/provider_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ std::set<std::string> provider::impl::get_active_users(const std::string& subkey
std::vector<std::string> indexes;
indexes.push_back(combine_key(subkey, boost::lexical_cast<std::string>(i)));
LOG(DNET_LOG_DEBUG, "Add index: '%s' to find request\n", indexes.back().c_str());
async_results.emplace_back(s.find_indexes(indexes));
async_results.emplace_back(s.find_all_indexes(indexes));
}

LOG(DNET_LOG_DEBUG, "Find indexes: %zd\n", async_results.size());
Expand Down

0 comments on commit 2ae3b24

Please sign in to comment.