code: public static String calculatePath(String uri) {
          if (!uri.startsWith("/")) {
              return "/";
          }
          int idx = uri.lastIndexOf('/');
          return uri.substring(0, idx + 1);
      }
docs: Get cookie default path from url path