<commit_before>var cache = {}

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 res = this.response
      , req = this.request
      , headers = res.getHeader( "Set-Cookie" ) || []
      , secure = res.socket ? res.socket.encrypted || req.connection.proxySecure : req.connection.proxySecure
      , cookie = new Cookie( name, value, opts )
      , header
      
    if ( typeof headers == "string" ) headers = [ headers ]
      
    if ( !secure && opts && opts.secure ) throw "Cannot send secure cookie over unencrypted socket"
    
    cookie.secure = secure
    if (opts && "secure" in opts) cookie.secure = opts.secure
    headers.push( cookie.toHeader() )
    
    if ( opts && opts.signed ) {
      cookie.value = this.keys.sign( cookie.toString() )
      cookie.name += ".sig"
      headers.push( cookie.toHeader() )
    }<commit_msg>Fix #10 Default signedness based on presence of keys<commit_after>var cache = {}

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
      , signed = opts && opts.signed !== undefined ? opts.signed : !!this.keys
      
    header = this.request.headers[ "cookie" ]
    if ( !header ) return    

    match = header.match( getPattern( name ) )
    if ( !match ) return
    
    value = match[ 1 ]
    if ( !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 res = this.response
      , req = this.request
      , headers = res.getHeader( "Set-Cookie" ) || []
      , secure = res.socket ? res.socket.encrypted || req.connection.proxySecure : req.connection.proxySecure
      , cookie = new Cookie( name, value, opts )
      , header
      , signed = opts && opts.signed !== undefined ? opts.signed : !!this.keys
      
    if ( typeof headers == "string" ) headers = [ headers ]
      
    if ( !secure && opts && opts.secure ) throw "Cannot send secure cookie over unencrypted socket"
    
    cookie.secure = secure
    if (opts && "secure" in opts) cookie.secure = opts.secure
    headers.push( cookie.toHeader() )
    
    if ( opts && signed ) {
      cookie.value = this.keys.sign( cookie.toString() )
      cookie.name += ".sig"
      headers.push( cookie.toHeader() )
    }
{'fraction_non_alphanumeric': 0.13477633477633477, 'fraction_numerical': 0.0017316017316017316, 'mean_word_length': 2.2728989612842305, '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': '3460647', 'n_tokens_mistral': 1076, 'n_tokens_neox': 1057, 'n_words': 304}