private Mono<DetectedEndpoint> detectEndpoint(Instance instance, EndpointDefinition endpoint) { String managementUrl = instance.getRegistration().getManagementUrl(); if (managementUrl == null) { return Mono.empty(); } URI uri = UriComponentsBuilder.fromUriString(managementUrl) .path("/") .path(endpoint.getPath()) .build() .toUri(); return instanceWebClient.instance(instance).options().uri(uri).exchange().flatMap(this.convert(endpoint, uri)); }
@Test public void testPreFlightCorsRequest() { ClientResponse clientResponse = webClient.options().uri("/abc/123/function") .header("Origin", "domain.com") .header("Access-Control-Request-Method", "GET").exchange().block(); HttpHeaders asHttpHeaders = clientResponse.headers().asHttpHeaders(); Mono<String> bodyToMono = clientResponse.bodyToMono(String.class); // pre-flight request shouldn't return the response body assertNull(bodyToMono.block()); assertEquals( "Missing header value in response: " + HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "*", asHttpHeaders.getAccessControlAllowOrigin()); assertEquals( "Missing header value in response: " + HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, Arrays.asList(new HttpMethod[] { HttpMethod.GET }), asHttpHeaders.getAccessControlAllowMethods()); assertEquals("Pre Flight call failed.", HttpStatus.OK, clientResponse.statusCode()); }