<commit_before>var cache = {}
  , isArray = Array.isArray

function Cookies( request, response, keys ) {
  this.request = request
  this.response = response
  this.keys = keys
}

Cookies.prototype = {
  get: function( name, opts ) {
    var sigName = name + ".sig"
      , header, match, value, remote, data, index
      
    header = this.request.headers[ "cookie" ]
    if ( !header ) return    

    match = header.match( getPattern( name ) )
    if ( !match ) return
    
    value = match[ 1 ]
    if ( !opts || !opts.signed ) return value

    remote = this.get( sigName )
    if ( !remote ) return
    
    data = name + "=" + value    
    index = this.keys.index( data, remote )

    if ( index < 0 ) this.set( sigName, null, { path: "/" } )
    
    else {
      index && this.set( sigName, this.keys.sign( data ) )
      return value
    }
  },
  
  set: function( name, value, opts ) {
    var header = this.response.getHeader( "Set-Cookie" )
      , cookie, str = name + "="
      
    value
      ? cookie = str += value
      : ( opts || ( opts = {} ) ).expires = new Date( 0 )

    str += "; path=" + ( opts && opts.path || "/" )
    
    if ( opts ) {
      if ( opts.expires  ) str += "; expires=" + opts.expires.toUTCString()
      if ( opts.domain   ) str += "; domain=" + opts.domain
      if ( opts.secure   ) str += "; secure"
      if ( opts.httpOnly ) str += "; httponly"
    }
    
    if ( !header ) header = str
    
    else {
      // TODO: check for existing header with same name
      isArray( header ) ? header.push( str ) : header = [ header, str ]
    }
    
    this.response.setHeader( "Set-Cookie", header )
    
    if ( !opts || !opts.signed ) return this
    
    opts = Object.create( opts )
    opts.signed = false
    
    return this.set( name + ".sig", value && this.keys.sign( cookie ), opts )
  }
}
<commit_msg>use httpOnly by default unless explicitly false<commit_after>var cache = {}
  , isArray = Array.isArray

function Cookies( request, response, keys ) {
  this.request = request
  this.response = response
  this.keys = keys
}

Cookies.prototype = {
  get: function( name, opts ) {
    var sigName = name + ".sig"
      , header, match, value, remote, data, index
      
    header = this.request.headers[ "cookie" ]
    if ( !header ) return    

    match = header.match( getPattern( name ) )
    if ( !match ) return
    
    value = match[ 1 ]
    if ( !opts || !opts.signed ) return value

    remote = this.get( sigName )
    if ( !remote ) return
    
    data = name + "=" + value    
    index = this.keys.index( data, remote )

    if ( index < 0 ) this.set( sigName, null, { path: "/" } )
    
    else {
      index && this.set( sigName, this.keys.sign( data ) )
      return value
    }
  },
  
  set: function( name, value, opts ) {
    var header = this.response.getHeader( "Set-Cookie" )
      , cookie, str = name + "="
      
    value
      ? cookie = str += value
      : ( opts || ( opts = {} ) ).expires = new Date( 0 )

    str += "; path=" + ( opts && opts.path || "/" )
    
    if ( opts ) {
      if ( opts.expires  ) str += "; expires=" + opts.expires.toUTCString()
      if ( opts.domain   ) str += "; domain=" + opts.domain
      if ( opts.secure   ) str += "; secure"
      if ( opts.httpOnly !== false ) str += "; httponly"
    }
    
    if ( !header ) header = str
    
    else {
      // TODO: check for existing header with same name
      isArray( header ) ? header.push( str ) : header = [ header, str ]
    }
    
    this.response.setHeader( "Set-Cookie", header )
    
    if ( !opts || !opts.signed ) return this
    
    opts = Object.create( opts )
    opts.signed = false
    
    return this.set( name + ".sig", value && this.keys.sign( cookie ), opts )
  }
}

{'fraction_non_alphanumeric': 0.14691817215727948, 'fraction_numerical': 0.001594048884165781, 'mean_word_length': 2.0047885075818037, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '5766059', 'n_tokens_mistral': 1224, 'n_tokens_neox': 1203, 'n_words': 339}