HttpServerHandler extends ChannelInboundHandlerAdapter { @VisibleForTesting static String stripContextPath(String path, String contextPath) { if (contextPath.equals("/")) { return path; } if (path.equals(contextPath)) { return "/"; } return path.substring(contextPath.length()); } HttpServerHandler(Supplier<String> contextPathSupplier, CommonHandler commonHandler); @Override void channelActive(ChannelHandlerContext ctx); @Override void channelReadComplete(ChannelHandlerContext ctx); @Override void channelRead(ChannelHandlerContext ctx, Object msg); @Override void exceptionCaught(ChannelHandlerContext ctx, Throwable cause);  }
@Test public void shouldStripContextPath() { assertThat(HttpServerHandler.stripContextPath("/one", "/")).isEqualTo("/one"); assertThat(HttpServerHandler.stripContextPath("/", "/")).isEqualTo("/"); assertThat(HttpServerHandler.stripContextPath("/one", "/one")).isEqualTo("/"); assertThat(HttpServerHandler.stripContextPath("/one/", "/one")).isEqualTo("/"); assertThat(HttpServerHandler.stripContextPath("/one/two", "/one")).isEqualTo("/two"); assertThat(HttpServerHandler.stripContextPath("/one/two/", "/one")).isEqualTo("/two/"); }