<commit_before>/*
 * SessionRequest.hpp
 *
 * Copyright (C) 2009-16 by RStudio, Inc.
 *
 * Unless you have received this program directly from RStudio pursuant
 * to the terms of a commercial license agreement with RStudio, then
 * this program is licensed to you under the terms of version 3 of the
 * GNU Affero General Public License. This program is distributed WITHOUT
 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
 *
 */

#ifndef SESSION_REQUEST_HPP
#define SESSION_REQUEST_HPP

#include <core/Error.hpp>
#include <core/system/Environment.hpp>

#include <session/http/SessionRequest.hpp>

#if !defined(_WIN32)
#include <core/http/TcpIpBlockingClient.hpp>
#include <core/http/LocalStreamBlockingClient.hpp>
#else
#include <core/http/NamedPipeBlockingClient.hpp>
#endif

#if !defined(_WIN32)
#include <session/SessionLocalStreams.hpp>
#endif

#include <session/SessionConstants.hpp>

namespace rstudio {
namespace session {
namespace http {
   
inline core::Error sendSessionRequest(const std::string& uri, 
      const std::string& body, core::http::Response* pResponse)
{
   // build request
   core::http::Request request;
   request.setMethod("POST");
   request.setUri(uri);
   request.setHeader("Accept", "*/*");
   request.setHeader("Connection", "close");
   request.setBody(body);
   std::cerr << "request: " << request << std::endl;

#ifdef _WIN32
   // get local peer
   std::string pipeName = core::system::getenv("RS_LOCAL_PEER");
   pRequest->setHeader("X-Shared-Secret",
                       core::system::getenv("RS_SHARED_SECRET"));
   return core::http::sendRequest(pipeName,
                            *pRequest,
                            ConnectionRetryProfile(
                                  boost::posix_time::seconds(10),
                                  boost::posix_time::milliseconds(50)),
                            pResponse);
#else
   std::string tcpipPort = core::system::getenv(kRSessionStandalonePortNumber);
   if (!tcpipPort.empty())
   {
      return core::http::sendRequest("127.0.0.1", tcpipPort, request, 
            pResponse);
   }
   else
   {
      // determine stream path
      std::string stream = core::system::getenv(kRStudioSessionStream);
      core::FilePath streamPath = session::local_streams::streamPath(stream);
      return core::http::sendRequest(streamPath, request, pResponse);
   }
#endif

   return core::Success();
}

} // namespace http
} // namespace session
} // namespace rstudio

#endif
<commit_msg>remove debug log & add comments for session request<commit_after>/*
 * SessionRequest.hpp
 *
 * Copyright (C) 2009-16 by RStudio, Inc.
 *
 * Unless you have received this program directly from RStudio pursuant
 * to the terms of a commercial license agreement with RStudio, then
 * this program is licensed to you under the terms of version 3 of the
 * GNU Affero General Public License. This program is distributed WITHOUT
 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
 *
 */

#ifndef SESSION_REQUEST_HPP
#define SESSION_REQUEST_HPP

#include <core/Error.hpp>
#include <core/system/Environment.hpp>

#include <session/http/SessionRequest.hpp>

#if !defined(_WIN32)
#include <core/http/TcpIpBlockingClient.hpp>
#include <core/http/LocalStreamBlockingClient.hpp>
#else
#include <core/http/NamedPipeBlockingClient.hpp>
#endif

#if !defined(_WIN32)
#include <session/SessionLocalStreams.hpp>
#endif

#include <session/SessionConstants.hpp>

namespace rstudio {
namespace session {
namespace http {
   
// this function sends an request directly to the session; it's inlined so that
// it can be used both from the postback executable (which does not link with
// rsession) and the session itself
inline core::Error sendSessionRequest(const std::string& uri, 
      const std::string& body, core::http::Response* pResponse)
{
   // build request
   core::http::Request request;
   request.setMethod("POST");
   request.setUri(uri);
   request.setHeader("Accept", "*/*");
   request.setHeader("Connection", "close");
   request.setBody(body);

#ifdef _WIN32
   // get local peer
   std::string pipeName = core::system::getenv("RS_LOCAL_PEER");
   pRequest->setHeader("X-Shared-Secret",
                       core::system::getenv("RS_SHARED_SECRET"));
   return core::http::sendRequest(pipeName,
                            *pRequest,
                            ConnectionRetryProfile(
                                  boost::posix_time::seconds(10),
                                  boost::posix_time::milliseconds(50)),
                            pResponse);
#else
   std::string tcpipPort = core::system::getenv(kRSessionStandalonePortNumber);
   if (!tcpipPort.empty())
   {
      return core::http::sendRequest("127.0.0.1", tcpipPort, request, 
            pResponse);
   }
   else
   {
      // determine stream path
      std::string stream = core::system::getenv(kRStudioSessionStream);
      core::FilePath streamPath = session::local_streams::streamPath(stream);
      return core::http::sendRequest(streamPath, request, pResponse);
   }
#endif

   return core::Success();
}

} // namespace http
} // namespace session
} // namespace rstudio

#endif

{'fraction_non_alphanumeric': 0.11690680284515775, 'fraction_numerical': 0.009119095385737734, 'mean_word_length': 3.39775461106656, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5559831', 'n_tokens_mistral': 1626, 'n_tokens_neox': 1565, 'n_words': 409}