disallowing a particular http method

114 views Asked by At

Related to https://github.com/openzipkin/zipkin/pull/3239 , we came across some (maybe) odd behaviour and i wanted to know if below test works as expected or not:

import com.linecorp.armeria.client.WebClient;
import com.linecorp.armeria.common.HttpMethod;
import com.linecorp.armeria.common.HttpRequest;
import com.linecorp.armeria.common.HttpResponse;
import com.linecorp.armeria.common.HttpStatus;
import com.linecorp.armeria.server.Server;
import com.linecorp.armeria.server.ServerBuilder;
import java.util.concurrent.CompletableFuture;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class ArmeriaTraceBug {

  @Test
  public void test_trace_bug() throws Exception {
    ServerBuilder sb = Server.builder();
    sb.http(7003);
    sb.service("/", (ctx, req) -> HttpResponse.of("Hello, world!"));
    sb.routeDecorator()
      .methods(HttpMethod.TRACE)
      .pathPrefix("/")
      .build((delegate, ctx, req) -> HttpResponse.of(HttpStatus.METHOD_NOT_ALLOWED));
    Server server = sb.build();
    CompletableFuture<Void> future = server.start();
    future.join();
    WebClient webClient = WebClient.of("http://localhost:7003/");
    final HttpResponse response = webClient.execute(HttpRequest.of(HttpMethod.OPTIONS, "/something"));
    assertThat(response.aggregate().get().status()).isEqualTo(HttpStatus.NOT_FOUND);
  }
}

Basically we wanted to disable all TRACE requests, and set pathPrefix("/") to achieve this. But for some reason the OPTIONS call to /something gets trapped in the same path. If i remove the route decorator things work as expected.

1

There are 1 answers

0
minwoox On BEST ANSWER

Thanks Jorg Heymans for the question. Yeah, it's a bug and should be fixed by https://github.com/line/armeria/pull/3120 Thank you!