Example #1
0
  protected void defaultServerSetup() {
    server();

    server.get(
        "/echo",
        new Handler() {

          @Override
          public Object handle(HttpExchange h) throws Exception {
            LowLevelHttpExchange x = (LowLevelHttpExchange) h;
            return x.verb_().get()
                + ":"
                + x.path_().get()
                + ":"
                + x.subpath_().get()
                + ":"
                + x.query_().get();
          }
        });

    server.get(
        "/hello",
        new Handler() {
          @Override
          public Object handle(HttpExchange x) {
            return "Hello";
          }
        });

    server.post(
        "/upload",
        new Handler() {
          @SuppressWarnings("unchecked")
          @Override
          public Object handle(HttpExchange x) {
            return U.join(
                ":",
                x.cookies().get("foo"),
                x.cookies().get("COOKIE1"),
                x.posted().get("a"),
                x.files().size(),
                Crypto.md5(x.files().get("f1")),
                Crypto.md5(x.files().get("f2")),
                Crypto.md5(U.or(x.files().get("f3"), new byte[0])));
          }
        });

    server.serve(
        new Handler() {
          @Override
          public Object handle(HttpExchange x) {
            return U.join(":", x.verb(), x.path(), x.subpath(), x.query());
          }
        });

    start();
  }