Skip to content

Commit

Permalink
Merge branch '4.1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
spencergibb committed Oct 31, 2024
2 parents c444594 + 7a41f6a commit 0b29d9f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.springframework.cloud.gateway.server.mvc.handler;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand Down Expand Up @@ -70,15 +69,9 @@ private static int copyBody(Request request, OutputStream outputStream) throws I
}

private ServerResponse doExchange(Request request, ClientHttpResponse clientResponse) throws IOException {
try {
InputStream body = clientResponse.getBody();
// put the body input stream in a request attribute so filters can read it.
MvcUtils.putAttribute(request.getServerRequest(), MvcUtils.CLIENT_RESPONSE_INPUT_STREAM_ATTR, body);
}
catch (FileNotFoundException e) {
// if using SimpleClientHttpRequestFactory
return ServerResponse.notFound().build();
}
InputStream body = clientResponse.getBody();
// put the body input stream in a request attribute so filters can read it.
MvcUtils.putAttribute(request.getServerRequest(), MvcUtils.CLIENT_RESPONSE_INPUT_STREAM_ATTR, body);
ServerResponse serverResponse = GatewayServerResponse.status(clientResponse.getStatusCode())
.build((req, httpServletResponse) -> {
try (clientResponse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,12 @@ public void stripPrefixPostWorks() {
public void setStatusGatewayRouterFunctionWorks() {
restClient.get()
.uri("/status/201")
.header("Host", "www.setstatus.org")
.exchange()
.expectStatus()
.isEqualTo(HttpStatus.TOO_MANY_REQUESTS)
.expectHeader()
.valueEquals("x-status", "201");
.valueEquals("x-status", "201"); // .expectBody(String.class).isEqualTo("Failed
// with 201");
}

@Test
Expand Down Expand Up @@ -981,11 +981,6 @@ public void clientResponseBodyAttributeWorks() {
});
}

@Test
public void notFoundWorks() {
restClient.get().uri("/status/404").header("Host", "www.notfound.org").exchange().expectStatus().isNotFound();
}

@SpringBootConfiguration
@EnableAutoConfiguration
@LoadBalancerClient(name = "httpbin", configuration = TestLoadBalancerConfig.Httpbin.class)
Expand Down Expand Up @@ -1037,7 +1032,7 @@ public RouterFunction<ServerResponse> gatewayRouterFunctionsAddReqHeader() {
public RouterFunction<ServerResponse> gatewayRouterFunctionsSetStatusAndAddRespHeader() {
// @formatter:off
return route("testsetstatus")
.GET("/status/{status}", host("**.setstatus.org"), http())
.GET("/status/{status}", http())
.before(new HttpbinUriResolver())
.after(setStatus(HttpStatus.TOO_MANY_REQUESTS))
.after(addResponseHeader("X-Status", "{status}"))
Expand Down Expand Up @@ -1605,16 +1600,6 @@ public RouterFunction<ServerResponse> gatewayRouterFunctionsReadResponseBody() {
// @formatter:on
}

@Bean
public RouterFunction<ServerResponse> gatewayRouterFunctions404() {
// @formatter:off
return route("testnotfound")
.GET("/status/404", host("**.notfound.org"), http())
.before(new HttpbinUriResolver())
.build();
// @formatter:on
}

@Bean
public FilterRegistrationBean myFilter() {
FilterRegistrationBean<MyFilter> reg = new FilterRegistrationBean<>(new MyFilter());
Expand Down

This file was deleted.

0 comments on commit 0b29d9f

Please sign in to comment.