Exemple #1
0
  private void doGet(OutputStream os, String url) throws IOException {
    if ("/".equals(url)) url = "/index.html";

    List<String> headers = new ArrayList<String>();
    headers.add("HTTP/1.1 200 OK\r\n");

    byte[] content = fm.get(url);

    if (content == null) {
      returnStatusCode(404, os);
      return;
    }

    ProcessorsList pl = new ProcessorsList();
    pl.add(new Compressor(6));
    // pl.add(new Chunker(30)); // comment
    content = pl.process(content, headers);

    if (content == null) {
      returnStatusCode(500, os);
      return;
    }

    // uncomment next line
    headers.add("Content-Length: " + content.length + "\r\n");
    headers.add("Connection: close\r\n\r\n");
    os.write(getBinaryHeaders(headers));
    os.write(content);
  }