@ -34,7 +34,9 @@ import org.springframework.cloud.gateway.test.BaseWebClientTests;
@@ -34,7 +34,9 @@ import org.springframework.cloud.gateway.test.BaseWebClientTests;
import org.springframework.context.annotation.Bean ;
import org.springframework.context.annotation.Import ;
import org.springframework.core.io.buffer.PooledDataBuffer ;
import org.springframework.http.HttpHeaders ;
import org.springframework.http.HttpStatus ;
import org.springframework.http.MediaType ;
import org.springframework.test.annotation.DirtiesContext ;
import org.springframework.util.StringUtils ;
import org.springframework.web.server.ServerWebExchange ;
@ -43,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@@ -43,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail ;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT ;
@SpringBootTest ( webEnvironment = RANDOM_PORT )
@SpringBootTest ( webEnvironment = RANDOM_PORT , properties = "spring.codec.max-in-memory-size=25" )
@DirtiesContext
public class CacheRequestBodyGatewayFilterFactoryTests extends BaseWebClientTests {
@ -53,6 +55,8 @@ public class CacheRequestBodyGatewayFilterFactoryTests extends BaseWebClientTest
@@ -53,6 +55,8 @@ public class CacheRequestBodyGatewayFilterFactoryTests extends BaseWebClientTest
private static final String BODY_CACHED_EXISTS = "BODY_CACHED_EXISTS" ;
private static final String LARGE_BODY_VALUE = "here is request body which will cause payload size failure" ;
@Test
public void cacheRequestBodyWorks ( ) {
testClient . post ( ) . uri ( "/post" ) . header ( "Host" , "www.cacherequestbody.org" ) . bodyValue ( BODY_VALUE ) . exchange ( )
@ -65,6 +69,14 @@ public class CacheRequestBodyGatewayFilterFactoryTests extends BaseWebClientTest
@@ -65,6 +69,14 @@ public class CacheRequestBodyGatewayFilterFactoryTests extends BaseWebClientTest
} ) ;
}
@Test
public void cacheRequestBodyDoesntWorkForLargePayload ( ) {
testClient . post ( ) . uri ( "/post" ) . header ( "Host" , "www.cacherequestbody.org" )
. header ( HttpHeaders . CONTENT_TYPE , MediaType . APPLICATION_JSON_VALUE ) . bodyValue ( LARGE_BODY_VALUE )
. exchange ( ) . expectStatus ( ) . isEqualTo ( HttpStatus . INTERNAL_SERVER_ERROR ) . expectBody ( ) . jsonPath ( "message" )
. isEqualTo ( "Exceeded limit on max bytes to buffer : 25" ) ;
}
@Test
public void cacheRequestBodyEmpty ( ) {
testClient . post ( ) . uri ( "/post" ) . header ( "Host" , "www.cacherequestbodyempty.org" ) . exchange ( ) . expectStatus ( ) . isOk ( )