<commit_before>package eu.w4.contrib.bpmnplus.module.httpd;

import java.io.File;
import java.io.IOException;
import java.net.URLConnection;
import java.net.URLDecoder;

import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.MethodNotSupportedException;
import org.apache.http.entity.ContentType;
import org.apache.http.nio.entity.NFileEntity;
import org.apache.http.nio.entity.NStringEntity;
import org.apache.http.nio.protocol.BasicAsyncRequestConsumer;
import org.apache.http.nio.protocol.BasicAsyncResponseProducer;
import org.apache.http.nio.protocol.HttpAsyncExchange;
import org.apache.http.nio.protocol.HttpAsyncRequestConsumer;
import org.apache.http.nio.protocol.HttpAsyncRequestHandler;
import org.apache.http.protocol.HttpContext;

class FileHandler implements HttpAsyncRequestHandler<HttpRequest>
{

  private static final String[] INDEXES = { "index.htm", "index.html", "default.htm", "default.html" };
  private final File _root;

  public FileHandler(final File docRoot)
  {
    super();
    this._root = docRoot;
  }

  public HttpAsyncRequestConsumer<HttpRequest> processRequest(final HttpRequest request,
                                                              final HttpContext context)
  {
    return new BasicAsyncRequestConsumer();
  }

  public void handle(final HttpRequest request,
                     final HttpAsyncExchange httpexchange,
                     final HttpContext context)
    throws HttpException, IOException
  {
    final HttpResponse response = httpexchange.getResponse();
    handleInternal(request, response, context);
    httpexchange.submitResponse(new BasicAsyncResponseProducer(response));
  }

  private void handleInternal(final HttpRequest request,
                              final HttpResponse response,
                              final HttpContext context)
    throws HttpException, IOException
  {

    final String method = request.getRequestLine().getMethod().toUpperCase();
    if (!method.equals("GET") && !method.equals("HEAD") && !method.equals("POST"))
    {
      throw new MethodNotSupportedException(method + " method not supported");
    }

    final String target = request.getRequestLine().getUri();
    final File file = new File(this._root, URLDecoder.decode(target, "UTF-8"));
    if (!file.exists())
    {<commit_msg>Bug fix: discard query part of URL when accessing file<commit_after>package eu.w4.contrib.bpmnplus.module.httpd;

import java.io.File;
import java.io.IOException;
import java.net.URLConnection;
import java.net.URLDecoder;

import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.MethodNotSupportedException;
import org.apache.http.entity.ContentType;
import org.apache.http.nio.entity.NFileEntity;
import org.apache.http.nio.entity.NStringEntity;
import org.apache.http.nio.protocol.BasicAsyncRequestConsumer;
import org.apache.http.nio.protocol.BasicAsyncResponseProducer;
import org.apache.http.nio.protocol.HttpAsyncExchange;
import org.apache.http.nio.protocol.HttpAsyncRequestConsumer;
import org.apache.http.nio.protocol.HttpAsyncRequestHandler;
import org.apache.http.protocol.HttpContext;

class FileHandler implements HttpAsyncRequestHandler<HttpRequest>
{

  private static final String[] INDEXES = { "index.htm", "index.html", "default.htm", "default.html" };
  private final File _root;

  public FileHandler(final File docRoot)
  {
    super();
    this._root = docRoot;
  }

  public HttpAsyncRequestConsumer<HttpRequest> processRequest(final HttpRequest request,
                                                              final HttpContext context)
  {
    return new BasicAsyncRequestConsumer();
  }

  public void handle(final HttpRequest request,
                     final HttpAsyncExchange httpexchange,
                     final HttpContext context)
    throws HttpException, IOException
  {
    final HttpResponse response = httpexchange.getResponse();
    handleInternal(request, response, context);
    httpexchange.submitResponse(new BasicAsyncResponseProducer(response));
  }

  private void handleInternal(final HttpRequest request,
                              final HttpResponse response,
                              final HttpContext context)
    throws HttpException, IOException
  {

    final String method = request.getRequestLine().getMethod().toUpperCase();
    if (!method.equals("GET") && !method.equals("HEAD") && !method.equals("POST"))
    {
      throw new MethodNotSupportedException(method + " method not supported");
    }

    String target = request.getRequestLine().getUri();
    if (target.indexOf('?') >= 0)
    {
      target = target.substring(0, target.indexOf('?'));
    }
    final File file = new File(this._root, URLDecoder.decode(target, "UTF-8"));
    if (!file.exists())
    {
{'fraction_non_alphanumeric': 0.10072376357056695, 'fraction_numerical': 0.0012062726176115801, 'mean_word_length': 3.6150278293135436, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '138814', 'n_tokens_mistral': 1339, 'n_tokens_neox': 1302, 'n_words': 288}