Exemple #1
0
  public void service(final RequestAdapter request, final ResponseAdapter response)
      throws IOException {

    final OutputStream out = response.getOutputStream();

    final ISocket fcgiSocket = connectionFactory.getConnection();
    fcgiSocket.setSoTimeout((int) READ_TIMEOUT);

    try {
      synchronized (fcgiSocket) {
        handleRequest(request, response, fcgiSocket, out, keepAlive);
      }
    } finally {
      if (fcgiSocket != null) {
        connectionFactory.releaseConnection(fcgiSocket);
      }
      fcgiSocket.close();
    }
  }
Exemple #2
0
  private int parseHeaders(final ResponseAdapter res, final InputStream is) throws IOException {
    String key = "";
    String value = "";

    int ch = is.read();

    if (ch < 0) {
      getLog().error("Can't contact FastCGI");
      res.sendError(HTTP_ERROR_BAD_GATEWAY);
      return -1;
    }

    while (ch >= 0) {
      key = "";
      value = "";

      while (ch >= 0 && ch != ' ' && ch != '\r' && ch != '\n' && ch != ':') {
        key += Character.toString((char) ch);
        ch = is.read();
      }

      while (ch >= 0 && ch == ' ' || ch == ':') {
        ch = is.read();
      }

      while (ch >= 0 && ch != '\r' && ch != '\n') {
        value += Character.toString((char) ch);
        ch = is.read();
      }

      if (ch == '\r') {
        ch = is.read();
        if (ch == '\n') {
          ch = is.read();
        }
      }

      if (key.length() == 0) {
        return ch;
      }

      if (getLog().isInfoEnabled()) {
        getLog().info("fastcgi:" + key + ": " + value);
      }

      if (key.equalsIgnoreCase("status")) {
        int status = 0;
        final int len = value.length();

        for (int i = 0; i < len; i++) {
          final char digit = value.charAt(i);

          if ('0' <= digit && digit <= '9') {
            status = 10 * status + digit - '0';
          } else {
            break;
          }
        }

        res.setStatus(status);
      } else if (key.equalsIgnoreCase("location")) {
        res.sendRedirect(value);
      } else {
        res.addHeader(key, value);
      }
    }

    return ch;
  }