private boolean dispatchToHandler()

in stetho/src/main/java/com/facebook/stetho/server/http/LightHttpServer.java [70:98]


  private boolean dispatchToHandler(
      SocketLike socketLike,
      LightHttpRequest request,
      LightHttpResponse response)
      throws IOException {
    HttpHandler handler = mHandlerRegistry.lookup(request.uri.getPath());
    if (handler == null) {
      response.code = HttpStatus.HTTP_NOT_FOUND;
      response.reasonPhrase = "Not found";
      response.body = LightHttpBody.create("No handler found\n", "text/plain");
      return true;
    } else {
      try {
        return handler.handleRequest(socketLike, request, response);
      } catch (RuntimeException e) {
        response.code = HttpStatus.HTTP_INTERNAL_SERVER_ERROR;
        response.reasonPhrase = "Internal Server Error";
        StringWriter stack = new StringWriter();
        PrintWriter stackWriter = new PrintWriter(stack);
        try {
          e.printStackTrace(stackWriter);
        } finally {
          stackWriter.close();
        }
        response.body = LightHttpBody.create(stack.toString(), "text/plain");
        return true;
      }
    }
  }