yu199195 commented on a change in pull request #2980:
URL: https://github.com/apache/incubator-shenyu/pull/2980#discussion_r819594951
##########
File path:
shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/NettyHttpClientPlugin.java
##########
@@ -75,37 +56,32 @@ public NettyHttpClientPlugin(final HttpClient httpClient) {
}
@Override
- public Mono<Void> execute(final ServerWebExchange exchange, final
ShenyuPluginChain chain) {
- final ShenyuContext shenyuContext =
exchange.getAttribute(Constants.CONTEXT);
- assert shenyuContext != null;
- ServerHttpRequest request = exchange.getRequest();
- final HttpMethod method = HttpMethod.valueOf(request.getMethodValue());
- HttpHeaders filtered = request.getHeaders();
+ protected HttpHeaders buildHttpHeaders(final ServerWebExchange exchange) {
final DefaultHttpHeaders httpHeaders = new DefaultHttpHeaders();
- filtered.forEach(httpHeaders::set);
+ exchange.getRequest().getHeaders().forEach(httpHeaders::set);
// remove gzip
- String acceptEncoding = httpHeaders.get(HttpHeaders.ACCEPT_ENCODING);
+ String acceptEncoding =
httpHeaders.get(HttpHeaderNames.ACCEPT_ENCODING);
if (StringUtils.isNotBlank(acceptEncoding)) {
List<String> acceptEncodings =
Stream.of(acceptEncoding.trim().split(",")).collect(Collectors.toList());
acceptEncodings.remove(Constants.HTTP_ACCEPT_ENCODING_GZIP);
- httpHeaders.set(HttpHeaders.ACCEPT_ENCODING, String.join(",",
acceptEncodings));
- }
- URI uri = exchange.getAttribute(Constants.HTTP_URI);
- if (Objects.isNull(uri)) {
- Object error = ShenyuResultWrap.error(exchange,
ShenyuResultEnum.CANNOT_FIND_URL, null);
- return WebFluxResultUtils.result(exchange, error);
+ httpHeaders.set(HttpHeaderNames.ACCEPT_ENCODING, String.join(",",
acceptEncodings));
}
- LOG.info("you request, The resulting urlPath is: {}",
uri.toASCIIString());
- Flux<HttpClientResponse> responseFlux =
this.httpClient.headers(headers -> headers.add(httpHeaders))
- .request(method).uri(uri.toASCIIString())
- .send((req, nettyOutbound) ->
nettyOutbound.send(request.getBody().map(dataBuffer -> ((NettyDataBuffer)
dataBuffer).getNativeBuffer())))
+ return httpHeaders;
+ }
+
+ @Override
+ protected Mono<?> doRequest(final ServerWebExchange exchange, final String
httpMethod, final URI uri,
+ final HttpHeaders httpHeaders, final
Flux<DataBuffer> body) {
+ return Mono.from(httpClient.headers(headers ->
headers.add(httpHeaders))
+
.request(HttpMethod.valueOf(httpMethod)).uri(uri.toASCIIString())
+ .send((req, nettyOutbound) ->
nettyOutbound.send(body.map(dataBuffer -> ((NettyDataBuffer)
dataBuffer).getNativeBuffer())))
.responseConnection((res, connection) -> {
exchange.getAttributes().put(Constants.CLIENT_RESPONSE_ATTR, res);
exchange.getAttributes().put(Constants.CLIENT_RESPONSE_CONN_ATTR, connection);
ServerHttpResponse response = exchange.getResponse();
- HttpHeaders headers = new HttpHeaders();
+ org.springframework.http.HttpHeaders headers = new
org.springframework.http.HttpHeaders();
Review comment:
is org.springframework.http.HttpHeaders, why not is NettyHttpHeader?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]