<commit_before>#ifndef SIMPLE_HTTP_REQUEST_H_
#define SIMPLE_HTTP_REQUEST_H_

#define  SIMPLE_HTTP_REQUEST_VERSION_MAJOR 0
#define  SIMPLE_HTTP_REQUEST_VERSION_MINOR 1
#define  SIMPLE_HTTP_REQUEST_VERSION_PATCH 0

#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <fstream>
#include <iostream>
#include <map>
#include <sstream>
#include <unistd.h>

#include "uv.h"
#include "http_parser.h"
#ifdef ENABLE_SSL
//#include "openssl/err.h"
#include "openssl/ssl.h"
#endif

namespace request {
using namespace std;

#ifndef ULLONG_MAX
# define ULLONG_MAX ((uint64_t) -1) /* 2^64-1 */
#endif

#if defined(NDEBUG)
# define ASSERT(exp)
#else
# define ASSERT(exp)  assert(exp)
#endif

// FIXME : to stderr with __LINE__, __PRETTY_FUNCTION__ ?
#define LOGE(...) LOGI(__VA_ARGS__)
void _LOGI(){}
template <typename T, typename ...Args>
void _LOGI(T t, Args && ...args)
{
  if (getenv("DEBUG_LOG")) {
    try {
      std::ofstream logFile;
      logFile.open(getenv("DEBUG_LOG"), std::ios::out | std::ios::app);
      logFile << std::forward<T>(t);
      logFile.close();
    } catch(const std::exception &e) {
      std::cerr << e.what() << std::endl;
    }
  } else
    std::cout << std::forward<T>(t);

  _LOGI(std::forward<Args>(args)...);
}
template <typename T, typename ...Args>
void LOGI(T t, Args && ...args)
{
  if (!getenv("DEBUG")) return;

  _LOGI("[" + std::to_string(getpid()) + "] ");  // insert pid
  _LOGI(std::forward<T>(t));
  _LOGI(std::forward<Args>(args)...);
  _LOGI('\n');
}


// Forward declaration
class Error;
class Response;
class SimpleHttpRequest;

template<class... T>
using Callback = std::map<std::string, std::function<void(T...)>>;

static uv_loop_t* uv_loop;
static uv_alloc_cb uvAllocCb = [](uv_handle_t* handle, size_t size, uv_buf_t* buf) {
  buf->base = (char*)malloc(size);
  buf->len = size;
};;

// Error
class Error {
public:
  Error(){};
  Error(string name, string message) : name(name), message(message) {};
  string name;
  string message;
};

// Response
class Response : public stringstream {
public:
  unsigned int statusCode = 0;
  map<string, string> headers;
};

// Http Client
class SimpleHttpRequest {
 public:
  SimpleHttpRequest(const map<string, string> &options, uv_loop_t *loop) :  SimpleHttpRequest(loop) {
    this->options = options;
  }
  SimpleHttpRequest(const map<string, string> &options, const map<string, string> &requestHeaders, uv_loop_t *loop) :  SimpleHttpRequest(loop) {
    this->options = options;
    this->requestHeaders = requestHeaders;
  }<commit_msg>implement constructor of SimpleHttpRequest(options, headers)<commit_after>#ifndef SIMPLE_HTTP_REQUEST_H_
#define SIMPLE_HTTP_REQUEST_H_

#define  SIMPLE_HTTP_REQUEST_VERSION_MAJOR 0
#define  SIMPLE_HTTP_REQUEST_VERSION_MINOR 1
#define  SIMPLE_HTTP_REQUEST_VERSION_PATCH 0

#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <fstream>
#include <iostream>
#include <map>
#include <sstream>
#include <unistd.h>

#include "uv.h"
#include "http_parser.h"
#ifdef ENABLE_SSL
//#include "openssl/err.h"
#include "openssl/ssl.h"
#endif

namespace request {
using namespace std;

#ifndef ULLONG_MAX
# define ULLONG_MAX ((uint64_t) -1) /* 2^64-1 */
#endif

#if defined(NDEBUG)
# define ASSERT(exp)
#else
# define ASSERT(exp)  assert(exp)
#endif

// FIXME : to stderr with __LINE__, __PRETTY_FUNCTION__ ?
#define LOGE(...) LOGI(__VA_ARGS__)
void _LOGI(){}
template <typename T, typename ...Args>
void _LOGI(T t, Args && ...args)
{
  if (getenv("DEBUG_LOG")) {
    try {
      std::ofstream logFile;
      logFile.open(getenv("DEBUG_LOG"), std::ios::out | std::ios::app);
      logFile << std::forward<T>(t);
      logFile.close();
    } catch(const std::exception &e) {
      std::cerr << e.what() << std::endl;
    }
  } else
    std::cout << std::forward<T>(t);

  _LOGI(std::forward<Args>(args)...);
}
template <typename T, typename ...Args>
void LOGI(T t, Args && ...args)
{
  if (!getenv("DEBUG")) return;

  _LOGI("[" + std::to_string(getpid()) + "] ");  // insert pid
  _LOGI(std::forward<T>(t));
  _LOGI(std::forward<Args>(args)...);
  _LOGI('\n');
}


// Forward declaration
class Error;
class Response;
class SimpleHttpRequest;

template<class... T>
using Callback = std::map<std::string, std::function<void(T...)>>;

static uv_loop_t* uv_loop;
static uv_alloc_cb uvAllocCb = [](uv_handle_t* handle, size_t size, uv_buf_t* buf) {
  buf->base = (char*)malloc(size);
  buf->len = size;
};;

// Error
class Error {
public:
  Error(){};
  Error(string name, string message) : name(name), message(message) {};
  string name;
  string message;
};

// Response
class Response : public stringstream {
public:
  unsigned int statusCode = 0;
  map<string, string> headers;
};

// Http Client
class SimpleHttpRequest {
 public:
  SimpleHttpRequest(const map<string, string> &options, uv_loop_t *loop) :  SimpleHttpRequest(loop) {
    this->options = options;
  }
  SimpleHttpRequest(const map<string, string> &options, const map<string, string> &requestHeaders) :  SimpleHttpRequest(uv_default_loop()) {
    this->options = options;
    this->requestHeaders = requestHeaders;
  }
  SimpleHttpRequest(const map<string, string> &options, const map<string, string> &requestHeaders, uv_loop_t *loop) :  SimpleHttpRequest(loop) {
    this->options = options;
    this->requestHeaders = requestHeaders;
  }
{'fraction_non_alphanumeric': 0.16019772976931526, 'fraction_numerical': 0.004027828634199927, 'mean_word_length': 4.726415094339623, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1163498', 'n_tokens_mistral': 1984, 'n_tokens_neox': 1928, 'n_words': 451}