<commit_before>'use strict';

/* globals querystring, global, https, http, api_timeout */

// constant variables
global.const = {
	AUTH_ACCESS_TOKEN_NAME : 'access_token',
	AUTH_REFRESH_TOKEN_NAME : 'refresh_token',
	AUTH_PATH_COMPONENT : 'oauth2',
	AUTH_PARAM_REMEMBER_ME : 'remember_me',
	BBB_CONTENT_TYPE : 'application/vnd.blinkboxbooks.data',
	AUTH_MAX_AGE : 1000*60*60*24*14, // 14 days
	REFRESH_TOKEN_PATH: '/oauth2/token',
	LOCAL_PATH : 'local',
	SIGN_OUT_PATH : '/signout',
	CLIENT_CONFIG_PATH: '/config',
	CREDIT_CARD_PATH: '/service/my/creditcards',
	BASKET_PATH: '/service/my/baskets',
	PURCHASE_PATH: '/service/my/payments',
	CLUBCARD_PATH: '/service/my/clubcards',
	CLUBCARD_VALIDATION_PATH: '/service/clubcards/validation',
	LIBRARY_PATH: '/service/my/library',
	EXPIRED_TOKEN: 'The access token expired',
	INVALID_TOKEN: 'Access token is invalid',
  UNVERIFIED_IDENTITY: 'User identity must be reverified'
};

/**
 * Services
 * User: esteban
 * Date: 17/05/2013
 * Time: 12:08
 * To change this template use File | Settings | File Templates.
 */
exports.getResults = function (req, res, options) {

  var proxy_request_body;

  // Build proxy request headers by copying across request headers from client request
  var headers = {};
  for(var header in req.headers) {
    if (req.headers.hasOwnProperty(header)) {
      if (!options.hasOwnProperty(header)) {
        if (header !== 'cookie') {   // don't copy across cookies
          headers[header] = req.headers[header];
        //  console.log(header+' '+req.headers[header]); // uncomment to debug request headers
        }
      }
    }
  }
  // if present, translate access_token cookie to OAuth2 Authorisation header with bearer token
  // NOTE: the node app may be communicating with services behind the same firewall or on a different domain entirely (as is the case with nodejs-internal)
  // so we don't want to add the OAUTH2 header if communicating on port 80
  if (req.cookies.hasOwnProperty(global.const.AUTH_ACCESS_TOKEN_NAME) && options.port !== 80) {
		headers.Authorization = 'Bearer '+ req.cookies[global.const.AUTH_ACCESS_TOKEN_NAME];<commit_msg>Add origin header in NodeJS proxy if not provided by the client browser.<commit_after>'use strict';

/* globals querystring, global, https, http, api_timeout */

// constant variables
global.const = {
	AUTH_ACCESS_TOKEN_NAME : 'access_token',
	AUTH_REFRESH_TOKEN_NAME : 'refresh_token',
	AUTH_PATH_COMPONENT : 'oauth2',
	AUTH_PARAM_REMEMBER_ME : 'remember_me',
	BBB_CONTENT_TYPE : 'application/vnd.blinkboxbooks.data',
	AUTH_MAX_AGE : 1000*60*60*24*14, // 14 days
	REFRESH_TOKEN_PATH: '/oauth2/token',
	LOCAL_PATH : 'local',
	SIGN_OUT_PATH : '/signout',
	CLIENT_CONFIG_PATH: '/config',
	CREDIT_CARD_PATH: '/service/my/creditcards',
	BASKET_PATH: '/service/my/baskets',
	PURCHASE_PATH: '/service/my/payments',
	CLUBCARD_PATH: '/service/my/clubcards',
	CLUBCARD_VALIDATION_PATH: '/service/clubcards/validation',
	LIBRARY_PATH: '/service/my/library',
	EXPIRED_TOKEN: 'The access token expired',
	INVALID_TOKEN: 'Access token is invalid',
  UNVERIFIED_IDENTITY: 'User identity must be reverified'
};

/**
 * Services
 * User: esteban
 * Date: 17/05/2013
 * Time: 12:08
 * To change this template use File | Settings | File Templates.
 */
exports.getResults = function (req, res, options) {

  var proxy_request_body;

  // Build proxy request headers by copying across request headers from client request
  var headers = {};
  for(var header in req.headers) {
    if (req.headers.hasOwnProperty(header)) {
      if (!options.hasOwnProperty(header)) {
        if (header !== 'cookie') {   // don't copy across cookies
          headers[header] = req.headers[header];
        //  console.log(header+' '+req.headers[header]); // uncomment to debug request headers
        }
      }
    }
  }

  // Add origin header if missing, as it's not set by Firefox/IE for same-domain requests,
  // but required for the services API:
  if (!headers.origin) {
    headers.origin = req.protocol + ':' + req.headers.host;
  }

  // if present, translate access_token cookie to OAuth2 Authorisation header with bearer token
  // NOTE: the node app may be communicating with services behind the same firewall or on a different domain entirely (as is the case with nodejs-internal)
  // so we don't want to add the OAUTH2 header if communicating on port 80
  if (req.cookies.hasOwnProperty(global.const.AUTH_ACCESS_TOKEN_NAME) && options.port !== 80) {
		headers.Authorization = 'Bearer '+ req.cookies[global.const.AUTH_ACCESS_TOKEN_NAME];
{'fraction_non_alphanumeric': 0.11645792133597012, 'fraction_numerical': 0.014941771039332015, 'mean_word_length': 4.149321266968326, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4097802', 'n_tokens_mistral': 1513, 'n_tokens_neox': 1450, 'n_words': 396}