This is an automated email from the ASF dual-hosted git repository.
xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 3e5353f [type: refactor] support websocket query parameters. (#2735)
3e5353f is described below
commit 3e5353f9de53b280ab5f8421680f173936cc04f1
Author: Qicz <[email protected]>
AuthorDate: Mon Jan 10 14:25:18 2022 +0800
[type: refactor] support websocket query parameters. (#2735)
---
.../org/apache/shenyu/plugin/websocket/WebSocketPlugin.java | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git
a/shenyu-plugin/shenyu-plugin-websocket/src/main/java/org/apache/shenyu/plugin/websocket/WebSocketPlugin.java
b/shenyu-plugin/shenyu-plugin-websocket/src/main/java/org/apache/shenyu/plugin/websocket/WebSocketPlugin.java
index 966d243..03db703 100644
---
a/shenyu-plugin/shenyu-plugin-websocket/src/main/java/org/apache/shenyu/plugin/websocket/WebSocketPlugin.java
+++
b/shenyu-plugin/shenyu-plugin-websocket/src/main/java/org/apache/shenyu/plugin/websocket/WebSocketPlugin.java
@@ -96,19 +96,24 @@ public class WebSocketPlugin extends AbstractShenyuPlugin {
Object error = ShenyuResultWrap.error(exchange,
ShenyuResultEnum.CANNOT_FIND_HEALTHY_UPSTREAM_URL, null);
return WebFluxResultUtils.result(exchange, error);
}
- URI wsRequestUrl =
UriComponentsBuilder.fromUri(URI.create(buildWsRealPath(upstream,
shenyuContext))).build().toUri();
+ URI wsRequestUrl =
UriComponentsBuilder.fromUri(URI.create(buildWsRealPath(exchange, upstream,
shenyuContext))).build().toUri();
LOG.info("you websocket urlPath is :{}", wsRequestUrl.toASCIIString());
HttpHeaders headers = exchange.getRequest().getHeaders();
return this.webSocketService.handleRequest(exchange, new
ShenyuWebSocketHandler(
wsRequestUrl, this.webSocketClient, filterHeaders(headers),
buildWsProtocols(headers)));
}
- private String buildWsRealPath(final Upstream upstream, final
ShenyuContext shenyuContext) {
+ private String buildWsRealPath(final ServerWebExchange exchange, final
Upstream upstream, final ShenyuContext shenyuContext) {
String protocol = upstream.getProtocol();
if (StringUtils.isEmpty(protocol)) {
protocol = "ws://";
}
- return protocol + upstream.getUrl() + shenyuContext.getMethod();
+ String path = shenyuContext.getMethod();
+ String query = exchange.getRequest().getURI().getQuery();
+ if (StringUtils.hasText(query)) {
+ path = String.join("?", path, query);
+ }
+ return protocol + upstream.getUrl() + path;
}
private List<String> buildWsProtocols(final HttpHeaders headers) {