Search in sources :

Example 16 with ServerHttpResponse

use of org.springframework.http.server.reactive.ServerHttpResponse in project spring-framework by spring-projects.

the class DefaultCorsProcessorTests method preflightRequestWithoutRequestMethod.

@Test
public void preflightRequestWithoutRequestMethod() throws Exception {
    ServerWebExchange exchange = preFlightRequest().header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1").toExchange();
    this.processor.processRequest(this.conf, exchange);
    ServerHttpResponse response = exchange.getResponse();
    assertFalse(response.getHeaders().containsKey(ACCESS_CONTROL_ALLOW_ORIGIN));
    assertEquals(HttpStatus.FORBIDDEN, response.getStatusCode());
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) ServerHttpResponse(org.springframework.http.server.reactive.ServerHttpResponse) Test(org.junit.Test)

Example 17 with ServerHttpResponse

use of org.springframework.http.server.reactive.ServerHttpResponse in project spring-framework by spring-projects.

the class DefaultCorsProcessorTests method preflightRequestWithNullConfig.

@Test
public void preflightRequestWithNullConfig() throws Exception {
    ServerWebExchange exchange = preFlightRequest().header(ACCESS_CONTROL_REQUEST_METHOD, "GET").toExchange();
    this.conf.addAllowedOrigin("*");
    this.processor.processRequest(null, exchange);
    ServerHttpResponse response = exchange.getResponse();
    assertFalse(response.getHeaders().containsKey(ACCESS_CONTROL_ALLOW_ORIGIN));
    assertEquals(HttpStatus.FORBIDDEN, response.getStatusCode());
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) ServerHttpResponse(org.springframework.http.server.reactive.ServerHttpResponse) Test(org.junit.Test)

Example 18 with ServerHttpResponse

use of org.springframework.http.server.reactive.ServerHttpResponse in project spring-framework by spring-projects.

the class DefaultCorsProcessorTests method actualRequestWithOriginHeaderAndNullConfig.

@Test
public void actualRequestWithOriginHeaderAndNullConfig() throws Exception {
    ServerWebExchange exchange = actualRequest();
    this.processor.processRequest(null, exchange);
    ServerHttpResponse response = exchange.getResponse();
    assertFalse(response.getHeaders().containsKey(ACCESS_CONTROL_ALLOW_ORIGIN));
    assertNull(response.getStatusCode());
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) ServerHttpResponse(org.springframework.http.server.reactive.ServerHttpResponse) Test(org.junit.Test)

Example 19 with ServerHttpResponse

use of org.springframework.http.server.reactive.ServerHttpResponse in project spring-framework by spring-projects.

the class DefaultCorsProcessorTests method actualRequestExposedHeaders.

@Test
public void actualRequestExposedHeaders() throws Exception {
    ServerWebExchange exchange = actualRequest();
    this.conf.addExposedHeader("header1");
    this.conf.addExposedHeader("header2");
    this.conf.addAllowedOrigin("http://domain2.com");
    this.processor.processRequest(this.conf, exchange);
    ServerHttpResponse response = exchange.getResponse();
    assertTrue(response.getHeaders().containsKey(ACCESS_CONTROL_ALLOW_ORIGIN));
    assertEquals("http://domain2.com", response.getHeaders().getFirst(ACCESS_CONTROL_ALLOW_ORIGIN));
    assertTrue(response.getHeaders().containsKey(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS));
    assertTrue(response.getHeaders().getFirst(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS).contains("header1"));
    assertTrue(response.getHeaders().getFirst(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS).contains("header2"));
    assertNull(response.getStatusCode());
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) ServerHttpResponse(org.springframework.http.server.reactive.ServerHttpResponse) Test(org.junit.Test)

Example 20 with ServerHttpResponse

use of org.springframework.http.server.reactive.ServerHttpResponse in project spring-framework by spring-projects.

the class DefaultCorsProcessorTests method preflightRequestWithEmptyHeaders.

@Test
public void preflightRequestWithEmptyHeaders() throws Exception {
    ServerWebExchange exchange = preFlightRequest().header(ACCESS_CONTROL_REQUEST_METHOD, "GET").header(ACCESS_CONTROL_REQUEST_HEADERS, "").toExchange();
    this.conf.addAllowedHeader("*");
    this.conf.addAllowedOrigin("http://domain2.com");
    this.processor.processRequest(this.conf, exchange);
    ServerHttpResponse response = exchange.getResponse();
    assertTrue(response.getHeaders().containsKey(ACCESS_CONTROL_ALLOW_ORIGIN));
    assertFalse(response.getHeaders().containsKey(ACCESS_CONTROL_ALLOW_HEADERS));
    assertNull(response.getStatusCode());
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) ServerHttpResponse(org.springframework.http.server.reactive.ServerHttpResponse) Test(org.junit.Test)

Aggregations

ServerHttpResponse (org.springframework.http.server.reactive.ServerHttpResponse)30 Test (org.junit.Test)21 ServerWebExchange (org.springframework.web.server.ServerWebExchange)20 ServerHttpRequest (org.springframework.http.server.reactive.ServerHttpRequest)6 ResolvableType (org.springframework.core.ResolvableType)4 MediaType (org.springframework.http.MediaType)4 Flux (reactor.core.publisher.Flux)4 IOException (java.io.IOException)3 Collections (java.util.Collections)3 Mono (reactor.core.publisher.Mono)3 List (java.util.List)2 Map (java.util.Map)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 ReactiveAdapter (org.springframework.core.ReactiveAdapter)2 DataBufferFactory (org.springframework.core.io.buffer.DataBufferFactory)2 HttpHeaders (org.springframework.http.HttpHeaders)2 HttpMethod (org.springframework.http.HttpMethod)2 ServletServerHttpRequest (org.springframework.http.server.reactive.ServletServerHttpRequest)2 ServletServerHttpResponse (org.springframework.http.server.reactive.ServletServerHttpResponse)2