<commit_before>module.exports = handler

var path = require('path')
var debug = require('debug')('ldnode:index')
var acl = require('../acl')
var get = require('./get')
var Negotiator = require('negotiator')

function handler (req, res, next) {
  var ldp = req.app.locals.ldp
  var negotiator = new Negotiator(req)
  var requestedType = negotiator.mediaType()

  if (requestedType.indexOf('text/html') !== 0) {
    return next()
  }

  res.locals.path = req.path
  if (req.path.indexOf('index.html') < 0) {
    res.locals.path = path.join(req.path, 'index.html')
  }
  debug('looking for ' + res.locals.path)

  // Check if file exists in first place
  ldp.exists(req.hostname, res.locals.path, function (err) {
    if (err) return next()
    debug('found an index for current path')
    // Since it exists, can the user read this?
    acl.allow('Read')(req, res, function (err) {
      if (err) return next()
      debug('current agent can read it')
      // Send the file
      get(req, res, function (err) {
        if (err) return next()
        debug('defaulting to index.html')
        // file is already sent, no action needed
      })
    })
  })
}<commit_msg>Reset path<commit_after>module.exports = handler

var path = require('path')
var debug = require('debug')('ldnode:index')
var acl = require('../acl')
var get = require('./get')
var Negotiator = require('negotiator')

function handler (req, res, next) {
  var ldp = req.app.locals.ldp
  var negotiator = new Negotiator(req)
  var requestedType = negotiator.mediaType()

  if (requestedType.indexOf('text/html') !== 0) {
    return next()
  }

  res.locals.path = req.path
  if (req.path.indexOf('index.html') < 0) {
    res.locals.path = path.join(req.path, 'index.html')
  }
  debug('looking for ' + res.locals.path)

  // Check if file exists in first place
  ldp.exists(req.hostname, res.locals.path, function (err) {
    if (err) {
      res.locals.path = req.path
      return next()
    }
    debug('found an index for current path')
    // Since it exists, can the user read this?
    acl.allow('Read')(req, res, function (err) {
      if (err) return next()
      debug('current agent can read it')
      // Send the file
      get(req, res, function (err) {
        if (err) return next()
        debug('defaulting to index.html')
        // file is already sent, no action needed
      })
    })
  })
}
{'fraction_non_alphanumeric': 0.14970563498738435, 'fraction_numerical': 0.001682085786375105, 'mean_word_length': 2.9128289473684212, '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': '2818479', 'n_tokens_mistral': 790, 'n_tokens_neox': 774, 'n_words': 225}