<commit_before>import { Injectable } from '@angular/core';
import { RequestOptions, RequestOptionsArgs, Headers } from '@angular/http';

/**
 * Work-around to the fact that Angular re-instantiates
 * RequestOptions internally for POST requests. Therefore
 * setting a property does not work and we have to resort
 * to using a static property on this ValueHolder class.
 */
class ValueHolder {
  static xAuthToken: string;
}

/**
 * A custom class extending {@link RequestOptions} to provide
 * the ability to use and set a custom xAuthToken header.
 *
 * @author <NAME>
 */
export class DefaultRequestOptions extends RequestOptions {

  constructor(options: RequestOptionsArgs) {
    super(options);
  }

  private xAuthTokenHeaderName = 'x-auth-token';

  merge(options: RequestOptions) {
    const newRequestOptions = super.merge(options);

    if (ValueHolder.xAuthToken) {
      if (!newRequestOptions.headers) {
        newRequestOptions.headers = new Headers();
      }
      newRequestOptions.headers.append(this.xAuthTokenHeaderName, ValueHolder.xAuthToken);
    }

    return new DefaultRequestOptions({
      method: newRequestOptions.method,
      headers: newRequestOptions.headers,
      body: newRequestOptions.body,
      url: newRequestOptions.url,
      search: newRequestOptions.search,<commit_msg>gh-832 Fix Triggering App Default fails with an infinite redirect<commit_after>import { Injectable } from '@angular/core';
import { RequestOptions, RequestOptionsArgs, Headers, RequestMethod } from '@angular/http';

/**
 * Work-around to the fact that Angular re-instantiates
 * RequestOptions internally for POST requests. Therefore
 * setting a property does not work and we have to resort
 * to using a static property on this ValueHolder class.
 */
class ValueHolder {
  static xAuthToken: string;
}

/**
 * A custom class extending {@link RequestOptions} to provide
 * the ability to use and set a custom xAuthToken header.
 *
 * @author <NAME>
 */
export class DefaultRequestOptions extends RequestOptions {

  constructor(options: RequestOptionsArgs) {
    super(options);
  }

  private xAuthTokenHeaderName = 'x-auth-token';

  merge(options: RequestOptions) {
    const newRequestOptions = super.merge(options);
    if (options.method === RequestMethod.Put) {
      return newRequestOptions;
    }
    if (ValueHolder.xAuthToken) {
      if (!newRequestOptions.headers) {
        newRequestOptions.headers = new Headers();
      }
      newRequestOptions.headers.append(this.xAuthTokenHeaderName, ValueHolder.xAuthToken);
    }
    return new DefaultRequestOptions({
      method: newRequestOptions.method,
      headers: newRequestOptions.headers,
      body: newRequestOptions.body,
      url: newRequestOptions.url,
      search: newRequestOptions.search,
{'fraction_non_alphanumeric': 0.08833034111310592, 'fraction_numerical': 0.0010771992818671453, 'mean_word_length': 3.975, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6099709', 'n_tokens_mistral': 749, 'n_tokens_neox': 730, 'n_words': 226}