@Override
  public void handle(final RoutingContext routingContext) {
    if (routingContext.request().isSSL()) {
      final String indicatedServerName = routingContext.request().connection()
          .indicatedServerName();
      final String requestHost = routingContext.request().host();
      if (indicatedServerName != null && requestHost != null) {
        // sometimes the port is present in the host header, remove it
        final String requestHostNoPort = requestHost.replaceFirst(":\\d+", "");
        if (!requestHostNoPort.equals(indicatedServerName)) {
          log.error(String.format(
              "Sni check failed, host header: %s, sni value %s",
              requestHostNoPort,
              indicatedServerName)
          );
          routingContext.fail(MISDIRECTED_REQUEST.code(),
              new KsqlApiException("This request was incorrectly sent to this ksqlDB server",
                  Errors.ERROR_CODE_MISDIRECTED_REQUEST));
          return;
        }
      }
    }
    routingContext.next();
  }
@Test
  public void shouldNotCheckIfSniNull() {
    // Given:
    when(httpConnection.indicatedServerName()).thenReturn(null);

    // When:
    sniHandler.handle(routingContext);

    // Then:
    verify(routingContext, never()).fail(anyInt(), any());
    verify(routingContext, times(1)).next();
  }