<commit_before>#= require _dom_parser

# if server responds with 304, sometimes you may get
# full page source instead of just wiselinks part, so
# you need to use different content extract strategies
class Response
  @_document_parser: null

  @_get_document_parser: ->
    Response._document_parser ?= new window._Wiselinks.DOMParser


  constructor: (@html, @xhr, @$target) ->

  url: ->
    @xhr.getResponseHeader('X-Wiselinks-Url')

  assets_digest: ->
    if @_is_full_document_response()
      $('meta[name="assets-digest"]', @_get_doc()).attr('content')
    else
      xhr.getResponseHeader('X-Wiselinks-Assets-Digest')

  content: ->
    @_content ?= @_extract_content()

  title: ->
    @_title ?= @_extract_title()

  _extract_title: ->
    if @_is_full_document_response()
      $('title', @_get_doc()).text()
    else
      @xhr.getResponseHeader('X-Wiselinks-Title')

  _extract_content: ->
    if @_is_full_document_response()
      @_get_doc_target_node().html()
    else
      @html

  _is_full_document_response: ->
    @_get_doc_target_node().length is 1
<commit_msg>fixed typo in xhr usage inside Response class<commit_after>#= require _dom_parser

# if server responds with 304, sometimes you may get
# full page source instead of just wiselinks part, so
# you need to use different content extract strategies
class Response
  @_document_parser: null

  @_get_document_parser: ->
    Response._document_parser ?= new window._Wiselinks.DOMParser


  constructor: (@html, @xhr, @$target) ->

  url: ->
    @xhr.getResponseHeader('X-Wiselinks-Url')

  assets_digest: ->
    if @_is_full_document_response()
      $('meta[name="assets-digest"]', @_get_doc()).attr('content')
    else
      @xhr.getResponseHeader('X-Wiselinks-Assets-Digest')

  content: ->
    @_content ?= @_extract_content()

  title: ->
    @_title ?= @_extract_title()

  _extract_title: ->
    if @_is_full_document_response()
      $('title', @_get_doc()).text()
    else
      @xhr.getResponseHeader('X-Wiselinks-Title')

  _extract_content: ->
    if @_is_full_document_response()
      @_get_doc_target_node().html()
    else
      @html

  _is_full_document_response: ->
    @_get_doc_target_node().length is 1

{'fraction_non_alphanumeric': 0.12834467120181406, 'fraction_numerical': 0.0036281179138321997, 'mean_word_length': 3.7956521739130435, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '2638766', 'n_tokens_mistral': 779, 'n_tokens_neox': 732, 'n_words': 153}