<commit_before>import * as db from '../../database';
import {getRenderedRequest} from '../render';
import {jarFromCookies} from '../cookies';

export function exportHar (requestId, addContentLength = false) {
  return new Promise((resolve, reject) => {
    db.requestGetById(requestId).then(request => {
      return getRenderedRequest(request);
    }).then(renderedRequest => {

      if (addContentLength) {
        const hasContentLengthHeader = !!renderedRequest.headers.find(
          h => h.name.toLowerCase() === 'content-length'
        );

        if (!hasContentLengthHeader) {
          const name = 'content-length';
          const value = Buffer.byteLength(renderedRequest.body).toString();
          renderedRequest.headers.push({name, value})
        }
      }

      resolve({
        method: renderedRequest.method,
        url: renderedRequest.url,
        httpVersion: 'HTTP/1.1',
        cookies: getCookies(renderedRequest),
        headers: renderedRequest.headers,
        postData: {
          text: renderedRequest.body
        },
        headersSize: -1,<commit_msg>Add querystring to har generator<commit_after>import * as db from '../../database';
import {getRenderedRequest} from '../render';
import {jarFromCookies} from '../cookies';

export function exportHar (requestId, addContentLength = false) {
  return new Promise((resolve, reject) => {
    db.requestGetById(requestId).then(request => {
      return getRenderedRequest(request);
    }).then(renderedRequest => {

      if (addContentLength) {
        const hasContentLengthHeader = !!renderedRequest.headers.find(
          h => h.name.toLowerCase() === 'content-length'
        );

        if (!hasContentLengthHeader) {
          const name = 'content-length';
          const value = Buffer.byteLength(renderedRequest.body).toString();
          renderedRequest.headers.push({name, value})
        }
      }

      resolve({
        method: renderedRequest.method,
        url: renderedRequest.url,
        httpVersion: 'HTTP/1.1',
        cookies: getCookies(renderedRequest),
        headers: renderedRequest.headers,
        queryString: renderedRequest.parameters,
        postData: {
          text: renderedRequest.body
        },
        headersSize: -1,
{'fraction_non_alphanumeric': 0.12455673758865249, 'fraction_numerical': 0.0026595744680851063, 'mean_word_length': 2.6879084967320264, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '7018607', 'n_tokens_mistral': 603, 'n_tokens_neox': 591, 'n_words': 127}