<commit_before>
var
  request = require('request');


var sparqlProxy = function (options) {
  return function (req, res, next) {
    var
      headers = {'Accept': req.headers.accept, 'Content-Type': 'application/sparql-query'},
      query;

    if (req.method === 'GET') {
      query = req.query.query;
    } else if (req.method === 'POST') {
      if ('query' in req.body) {
        query = req.body.query;
      } else {
        query = req.body;
      }
    } else {
      return next();
    }

    log.info({script: __filename}, 'handle SPARQL request for endpoint: ' + options.endpointUrl);
    log.debug({script: __filename}, 'SPARQL query:' + query);

    request
      .post(options.endpointUrl, {headers: headers, body: query})
      .pipe(res);
  };
};<commit_msg>support different query operations in SPARQL proxy<commit_after>
var
  request = require('request');

var directPost = function (req, res, endpointUrl, query) {
  headers = {'Accept': req.headers.accept, 'Content-Type': 'application/sparql-query'};

  request
    .post(endpointUrl, {headers: headers, body: query})
    .pipe(res);
}

var urlencodedPost = function (req, res, endpointUrl, query) {
  var headers = {'Accept': req.headers.accept, 'Content-Type': 'application/x-www-form-urlencoded'};

  request
    .post(endpointUrl, {headers: headers, form: {query: query}})
    .pipe(res);
}

var sparqlProxy = function (options) {
  return function (req, res, next) {
    var query;

    if (req.method === 'GET') {
      query = req.query.query;
    } else if (req.method === 'POST') {
      if ('query' in req.body) {
        query = req.body.query;
      } else {
        query = req.body;
      }
    } else {
      return next();
    }

    log.info({script: __filename}, 'handle SPARQL request for endpoint: ' + options.endpointUrl);
    log.debug({script: __filename}, 'SPARQL query:' + query);

    switch(options.queryOperation) {
      case 'urlencoded':
        return urlencodedPost(req, res, options.endpointUrl, query)
      default:
        return directPost(req, res, options.endpointUrl, query)
    }
  };
};
{'fraction_non_alphanumeric': 0.15296912114014252, 'fraction_numerical': 0.0, 'mean_word_length': 2.9144981412639406, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '1734348', 'n_tokens_mistral': 667, 'n_tokens_neox': 657, 'n_words': 170}