<commit_before>import { urlEncode, getAllResponseHeaders } from './utils'
import HttpProviderError from './HttpProviderError'

export default {
  method: 'get',
  baseUrl: '',
  headers: {
    'Content-Type': 'application/json; charset=UTF-8',
    Accept: 'application/json',
  },
  onRequest(xhr, options) {
    if (
      options.headers['Content-Type'] === 'application/x-www-form-urlencoded'
    ) {
      options.body = urlEncode(options.body)
    } else if (
      options.headers['Content-Type'].indexOf('application/json') >= 0
    ) {
      options.body = JSON.stringify(options.body)
    }

    xhr.withCredentials = Boolean(options.withCredentials)

    Object.keys(options.headers).forEach(key => {
      xhr.setRequestHeader(key, options.headers[key])
    })

    xhr.send(options.body)
  },
  onResponse(xhr, resolve, reject) {
    let result = xhr.responseText

    if (
      result &&
      xhr.getResponseHeader('Content-Type').indexOf('application/json') >= 0
    ) {
      result = JSON.parse(xhr.responseText)
    }<commit_msg>fix(http): fix error indexOf of undefined, if there are no headers in the server response (#952)<commit_after>import { urlEncode, getAllResponseHeaders } from './utils'
import HttpProviderError from './HttpProviderError'

export default {
  method: 'get',
  baseUrl: '',
  headers: {
    'Content-Type': 'application/json; charset=UTF-8',
    Accept: 'application/json',
  },
  onRequest(xhr, options) {
    if (
      options.headers['Content-Type'] === 'application/x-www-form-urlencoded'
    ) {
      options.body = urlEncode(options.body)
    } else if (
      options.headers['Content-Type'].indexOf('application/json') >= 0
    ) {
      options.body = JSON.stringify(options.body)
    }

    xhr.withCredentials = Boolean(options.withCredentials)

    Object.keys(options.headers).forEach(key => {
      xhr.setRequestHeader(key, options.headers[key])
    })

    xhr.send(options.body)
  },
  onResponse(xhr, resolve, reject) {
    let result = xhr.responseText

    if (
      result &&
      (xhr.getResponseHeader('Content-Type') || '')
        .indexOf('application/json') >= 0
    ) {
      result = JSON.parse(xhr.responseText)
    }
{'fraction_non_alphanumeric': 0.14799635701275046, 'fraction_numerical': 0.004098360655737705, 'mean_word_length': 3.184761904761905, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1215818', 'n_tokens_mistral': 692, 'n_tokens_neox': 676, 'n_words': 118}