<commit_before>fs = require('fs')
_console = require('PrettyConsole')

module.exports = class CompiledFile

  constructor: (conf) ->
    @route = conf.route
    @source = conf.source
    @debug = conf.debug
    @silent = conf.silent
    @tokens = conf.tokens
    @compiling = false
    @sourceFiles = []
    @hasBuildError = false
    @withWatchers = {}
    
    if conf.ttl
      setInterval(=>
        @build()
      , conf.ttl)


  setUp: () ->
    @


  responder: (stringFile, req, res) ->
    done = ()=>
      if @hasBuildError
        res.writeHead(424)
        res.end()
        return

      if req.headers['if-none-match'] isnt undefined and req.headers['if-none-match'] is stringFile.etag
        res.writeHead(304,
          'ETag': stringFile.etag
          'Content-Type': stringFile.contentType
        )    
        res.end()    
      else
        res.writeHead(200,
          'ETag': stringFile.etag
          'Content-Type': stringFile.contentType
        )
        res.end(stringFile.contents)
    
    if typeof @tokens is 'function'
      @build(=>
        done()
      )
    else
      done()
<commit_msg>adding cache-control headers<commit_after>fs = require('fs')
_console = require('PrettyConsole')

module.exports = class CompiledFile

  constructor: (conf) ->
    @route = conf.route
    @source = conf.source
    @debug = conf.debug
    @silent = conf.silent
    @tokens = conf.tokens
    @compiling = false
    @sourceFiles = []
    @hasBuildError = false
    @withWatchers = {}
    
    if conf.ttl
      setInterval(=>
        @build()
      , conf.ttl)


  setUp: () ->
    @


  responder: (stringFile, req, res) ->
    done = ()=>
      if @hasBuildError
        res.writeHead(424)
        res.end()
        return
      
      resOb = 
        'ETag': stringFile.etag
        'Content-Type': stringFile.contentType
        'Cache-Control': 'must-revalidate, post-check=0, pre-check=0'

      if req.headers['if-none-match'] isnt undefined and req.headers['if-none-match'] is stringFile.etag
        res.writeHead(304, resOb)    
        res.end()    
      else
        res.writeHead(200, resOb)
        res.end(stringFile.contents)
    
    if typeof @tokens is 'function'
      @build(=>
        done()
      )
    else
      done()

{'fraction_non_alphanumeric': 0.12764084507042253, 'fraction_numerical': 0.008802816901408451, 'mean_word_length': 1.9557867360208063, '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': '1169253', 'n_tokens_mistral': 749, 'n_tokens_neox': 723, 'n_words': 147}