<commit_before>class @HTTP
  @active_requests: {}
  MAX_NUM_RETRIES: 3

  constructor: (@method, @url, @data, callback) ->
    @key = "#{@method}:#{@url}:#{JSON.stringify(@data || '{}')}"
    if request = HTTP.active_requests[@key]
      return request.callbacks.push(callback)
    else
      HTTP.active_requests[@key] = @

    @callbacks = if callback then [callback] else []

    @retry_count = 0

    @retry_arguments = _.inject(arguments, ((memo, i)-> memo.push(i); memo), [])
    @retry = =>
      http = new HTTP @retry_arguments...
      http.callbacks = @callbacks

    @request = new HTTP.Request

    if @method == 'GET'
      params = for k,v of @data
        v = if v and typeof v == 'object' and v.length
          _.map(v, (_i) -> encodeURIComponent(_i)).join(',')
        else
          encodeURIComponent(v)
        "#{encodeURIComponent(k)}=#{v}"
      separator = if @url.match(/\?/) then "&" else "?"
      @url += "#{separator}#{params.join('&')}" if params.length
      @data = null

    uri = new HTTP.URI @url
    @host = uri.hostname
    @path = uri.path
    @port = uri.port

    @sendRequest()

  setHeader: => @request.setHeader(arguments...)
  sendRequest: =>
    return unless @request

    @request.open(@method, @url)

    data = if @data then JSON.stringify(@data) else null
    data = null if data == "{}" or data == "[]"

    if data && ["POST", "PUT", "PATCH"].indexOf(@method.toUpperCase()) != -1
      @request.setHeader('Content-type','application/vnd.tent.v0+json')

    uri = new HTTP.URI @url
    if TentStatus.current_auth_details.mac_key and uri.hostname == TentStatus.config.current_entity.hostname
      (new TentStatus.MacAuth
        request: @
        body: data
        mac_key: TentStatus.current_auth_details.mac_key
        mac_key_id: TentStatus.current_auth_details.mac_key_id<commit_msg>Fix: Use tent_api_root instead of current_entity when determining to sign request<commit_after>class @HTTP
  @active_requests: {}
  MAX_NUM_RETRIES: 3

  constructor: (@method, @url, @data, callback) ->
    @key = "#{@method}:#{@url}:#{JSON.stringify(@data || '{}')}"
    if request = HTTP.active_requests[@key]
      return request.callbacks.push(callback)
    else
      HTTP.active_requests[@key] = @

    @callbacks = if callback then [callback] else []

    @retry_count = 0

    @retry_arguments = _.inject(arguments, ((memo, i)-> memo.push(i); memo), [])
    @retry = =>
      http = new HTTP @retry_arguments...
      http.callbacks = @callbacks

    @request = new HTTP.Request

    if @method == 'GET'
      params = for k,v of @data
        v = if v and typeof v == 'object' and v.length
          _.map(v, (_i) -> encodeURIComponent(_i)).join(',')
        else
          encodeURIComponent(v)
        "#{encodeURIComponent(k)}=#{v}"
      separator = if @url.match(/\?/) then "&" else "?"
      @url += "#{separator}#{params.join('&')}" if params.length
      @data = null

    uri = new HTTP.URI @url
    @host = uri.hostname
    @path = uri.path
    @port = uri.port

    @sendRequest()

  setHeader: => @request.setHeader(arguments...)
  sendRequest: =>
    return unless @request

    @request.open(@method, @url)

    data = if @data then JSON.stringify(@data) else null
    data = null if data == "{}" or data == "[]"

    if data && ["POST", "PUT", "PATCH"].indexOf(@method.toUpperCase()) != -1
      @request.setHeader('Content-type','application/vnd.tent.v0+json')

    uri = new HTTP.URI @url
    if TentStatus.current_auth_details.mac_key and uri.hostname == TentStatus.config.tent_api_root.hostname
      (new TentStatus.MacAuth
        request: @
        body: data
        mac_key: TentStatus.current_auth_details.mac_key
        mac_key_id: TentStatus.current_auth_details.mac_key_id
{'fraction_non_alphanumeric': 0.15800692779110045, 'fraction_numerical': 0.0021316280309086064, 'mean_word_length': 2.9063475546305932, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '501502', 'n_tokens_mistral': 1241, 'n_tokens_neox': 1240, 'n_words': 277}