<commit_before>@Grab(group='org.mortbay.jetty', module='jetty-embedded', version='6.1.26')
import org.mortbay.jetty.Server
import org.mortbay.jetty.servlet.*
import groovy.servlet.*

import javax.servlet.Filter
import javax.servlet.FilterChain
import javax.servlet.FilterConfig
import javax.servlet.ServletException
import javax.servlet.ServletRequest
import javax.servlet.ServletResponse
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

def startJetty() {
    def jetty = new Server(8888)

    def context = new Context(jetty, '/', Context.SESSIONS)  // Allow sessions.
    context.setInitParams()
    context.resourceBase = '.'  // Look in current dir for Groovy scripts.
    context.addServlet(GroovyServlet, '/*')  // All files ending with .groovy will be served.
    context.addFilter(RedirectFilter, '/', 1)
    context.addFilter(DropFilter, '/*', 1)
    jetty.start()
}
 
println "Starting Jetty, press Ctrl+C to stop."
startJetty()
return

class RedirectFilter implements Filter {
    @Override
    void init(FilterConfig filterConfig) throws ServletException { /* NOP */ }

    @Override
    void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse) servletResponse
        response.sendRedirect('http://api.lappsgrid.org/info')
    }

    @Override
    void destroy() { /* NOP */ }
}

class DropFilter implements Filter {

    @Override
    void init(FilterConfig filterConfig) throws ServletException { /* NOP */ }

    @Override
    void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest
        println "FILTERING " + request.pathInfo
        if (accept(request.pathInfo)) {
            chain.doFilter(servletRequest, servletResponse)
        }
        else {
            HttpServletResponse response = (HttpServletResponse) servletResponse
            response.sendError(404, "Not found")
        }
    }

    @Override
    void destroy() { /* NOP */ }

    private boolean accept(String path) {
        if (path.startsWith('/templates')) return false
        if (path.startsWith('/.git')) return false
        if (path.startsWith('/groovlets')) return false
        if (path == '/') return false
        return true
    }
}<commit_msg>Renamed DropFilter<commit_after>@Grab(group='org.mortbay.jetty', module='jetty-embedded', version='6.1.26')
import org.mortbay.jetty.Server
import org.mortbay.jetty.servlet.*
import groovy.servlet.*

import javax.servlet.Filter
import javax.servlet.FilterChain
import javax.servlet.FilterConfig
import javax.servlet.ServletException
import javax.servlet.ServletRequest
import javax.servlet.ServletResponse
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

def startJetty() {
    def jetty = new Server(8888)

    def context = new Context(jetty, '/', Context.SESSIONS)  // Allow sessions.
    context.setInitParams()
    context.resourceBase = '.'  // Look in current dir for Groovy scripts.
    context.addServlet(GroovyServlet, '/*')  // All files ending with .groovy will be served.
    context.addFilter(RedirectFilter, '/', 1)
    context.addFilter(NotFoundFilter, '/*', 1)
    jetty.start()
}
 
println "Starting Jetty, press Ctrl+C to stop."
startJetty()
return

/** Redirect everything to the /info page. */
class RedirectFilter implements Filter {
    @Override
    void init(FilterConfig filterConfig) throws ServletException { /* NOP */ }

    @Override
    void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse) servletResponse
        response.sendRedirect('http://api.lappsgrid.org/info')
    }

    @Override
    void destroy() { /* NOP */ }
}

/** Return a 404 for matching paths */
class NotFoundFilter implements Filter {

    @Override
    void init(FilterConfig filterConfig) throws ServletException { /* NOP */ }

    @Override
    void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest
        if (accept(request.pathInfo)) {
            chain.doFilter(servletRequest, servletResponse)
        }
        else {
            HttpServletResponse response = (HttpServletResponse) servletResponse
            response.sendError(404, "Not found")
        }
    }

    @Override
    void destroy() { /* NOP */ }

    private boolean accept(String path) {
        if (path.startsWith('/templates')) return false
        if (path.startsWith('/.git')) return false
        if (path.startsWith('/groovlets')) return false
        return true
    }
}
{'fraction_non_alphanumeric': 0.10252808988764045, 'fraction_numerical': 0.005818619582664527, 'mean_word_length': 3.5525114155251143, 'pattern_counts': {'":': 0, '<': 3, '<?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': '599755', 'n_tokens_mistral': 1383, 'n_tokens_neox': 1334, 'n_words': 342}