Skip to content

Commit

Permalink
Merge branch 'master' into dubbo-example
Browse files Browse the repository at this point in the history
  • Loading branch information
moremind authored Oct 16, 2023
2 parents 68780c5 + e6ec95b commit 10ff60a
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion shenyu-bootstrap/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ shenyu:
# keyCertChainFile: '/Users/zhukunshuai/Desktop/cert/example.com+1.pem'
# keyFile: '/Users/zhukunshuai/Desktop/cert/example.com+1-key.pem'
# httpclient:
# strategy: webClient # netty
# strategy: netty # webClient
# connectTimeout: 45000
# responseTimeout: 3000
# readerIdleTime: 3000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ shenyu:
# keyCertChainFile: '/Users/zhukunshuai/Desktop/cert/example.com+1.pem'
# keyFile: '/Users/zhukunshuai/Desktop/cert/example.com+1-key.pem'
# httpclient:
# strategy: webClient # netty
# strategy: netty # webClient
# connectTimeout: 45000
# responseTimeout: 3000
# readerIdleTime: 3000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ shenyu:
# keyCertChainFile: '/Users/zhukunshuai/Desktop/cert/example.com+1.pem'
# keyFile: '/Users/zhukunshuai/Desktop/cert/example.com+1-key.pem'
# httpclient:
# strategy: webClient # netty
# strategy: netty # webClient
# connectTimeout: 45000
# responseTimeout: 3000
# readerIdleTime: 3000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ shenyu:
# keyCertChainFile: '/Users/zhukunshuai/Desktop/cert/example.com+1.pem'
# keyFile: '/Users/zhukunshuai/Desktop/cert/example.com+1-key.pem'
# httpclient:
# strategy: webClient # netty
# strategy: netty # webClient
# connectTimeout: 45000
# responseTimeout: 3000
# readerIdleTime: 3000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ shenyu:
# keyCertChainFile: '/Users/zhukunshuai/Desktop/cert/example.com+1.pem'
# keyFile: '/Users/zhukunshuai/Desktop/cert/example.com+1-key.pem'
# httpclient:
# strategy: webClient # netty
# strategy: netty # webClient
# connectTimeout: 45000
# responseTimeout: 3000
# readerIdleTime: 3000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ shenyu:
# keyCertChainFile: '/Users/zhukunshuai/Desktop/cert/example.com+1.pem'
# keyFile: '/Users/zhukunshuai/Desktop/cert/example.com+1-key.pem'
# httpclient:
# strategy: webClient # netty
# strategy: netty # webClient
# connectTimeout: 45000
# responseTimeout: 3000
# readerIdleTime: 3000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import org.apache.shenyu.common.utils.JsonUtils;
import org.apache.shenyu.common.utils.ObjectTypeUtils;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Flux;
import reactor.netty.http.client.HttpClientResponse;

import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -69,6 +71,13 @@ default Object format(ServerWebExchange exchange, Object origin) {
* @return the context type
*/
default MediaType contentType(ServerWebExchange exchange, Object formatted) {
final Object webHandlerClientResponse = exchange.getAttribute(Constants.CLIENT_RESPONSE_ATTR);
if (Objects.nonNull(webHandlerClientResponse) && webHandlerClientResponse instanceof HttpClientResponse) {
final HttpClientResponse httpClientResponse = (HttpClientResponse) webHandlerClientResponse;
final String contentType = httpClientResponse.responseHeaders().get(HttpHeaders.CONTENT_TYPE);
return Optional.ofNullable(contentType).map(MediaType::parseMediaType).orElse(MediaType.APPLICATION_JSON);
}

final ResponseEntity<Flux<DataBuffer>> fluxResponseEntity = exchange.getAttribute(Constants.CLIENT_RESPONSE_ATTR);
if (Objects.nonNull(fluxResponseEntity) && Optional.ofNullable(fluxResponseEntity.getHeaders().getContentType()).isPresent()) {
return fluxResponseEntity.getHeaders().getContentType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public HttpClientFactory httpClient(final HttpClientProperties properties,
* The type Web client configuration.
*/
@Configuration
@ConditionalOnProperty(name = "shenyu.httpclient.strategy", havingValue = "webClient", matchIfMissing = true)
@ConditionalOnProperty(name = "shenyu.httpclient.strategy", havingValue = "webClient")
static class WebClientConfiguration {

/**
Expand Down Expand Up @@ -130,7 +130,7 @@ public ShenyuPlugin webClientPlugin(
* The type Netty http client configuration.
*/
@Configuration
@ConditionalOnProperty(name = "shenyu.httpclient.strategy", havingValue = "netty")
@ConditionalOnProperty(name = "shenyu.httpclient.strategy", havingValue = "netty", matchIfMissing = true)
static class NettyHttpClientConfiguration {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public MessageWriter rpcMessageWriter() {
* The type Web client message writer configuration.
*/
@Configuration
@ConditionalOnProperty(name = "shenyu.httpclient.strategy", havingValue = "webClient", matchIfMissing = true)
@ConditionalOnProperty(name = "shenyu.httpclient.strategy", havingValue = "webClient")
static class WebClientMessageWriterConfiguration {

/**
Expand All @@ -92,7 +92,7 @@ public MessageWriter webClientMessageWriter() {
* The type Netty client message writer configuration.
*/
@Configuration
@ConditionalOnProperty(name = "shenyu.httpclient.strategy", havingValue = "netty")
@ConditionalOnProperty(name = "shenyu.httpclient.strategy", havingValue = "netty", matchIfMissing = true)
static class NettyClientMessageWriterConfiguration {

/**
Expand Down

0 comments on commit 10ff60a

Please sign in to comment.