Merge branch 'develop' of github.com:wehotel/fizz-gateway-community into develop
This commit is contained in:
@@ -9,11 +9,10 @@
|
||||
<version>2.2.13.RELEASE</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<groupId>com.fizzgate</groupId>
|
||||
<artifactId>fizz-bootstrap</artifactId>
|
||||
|
||||
<version>2.3.3-beta2</version>
|
||||
|
||||
<version>2.3.3-beta3</version>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
|
||||
@@ -5,12 +5,11 @@
|
||||
<parent>
|
||||
<artifactId>fizz-gateway-community</artifactId>
|
||||
<groupId>com.fizzgate</groupId>
|
||||
|
||||
<version>2.3.3-beta2</version>
|
||||
|
||||
<version>2.3.3-beta3</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>fizz-common</artifactId>
|
||||
|
||||
<properties>
|
||||
|
||||
@@ -17,16 +17,28 @@
|
||||
|
||||
package we.spring.http.server.reactive.ext;
|
||||
|
||||
import io.netty.handler.codec.http.cookie.Cookie;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.NettyDataBuffer;
|
||||
import org.springframework.core.io.buffer.PooledDataBuffer;
|
||||
import org.springframework.http.HttpCookie;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.server.reactive.AbstractServerHttpRequest;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.StringUtils;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.netty.http.server.HttpServerRequest;
|
||||
import we.util.NettyDataBufferUtils;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author hongqiaowei
|
||||
@@ -34,20 +46,87 @@ import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class FizzServerHttpRequestDecorator extends ServerHttpRequestDecorator {
|
||||
|
||||
private static final Pattern QUERY_PATTERN = Pattern.compile("([^&=]+)(=?)([^&]+)?");
|
||||
|
||||
private AbstractServerHttpRequest delegate;
|
||||
|
||||
private HttpServerRequest nativeRequest;
|
||||
|
||||
@Nullable
|
||||
private MultiValueMap<String, String> queryParams;
|
||||
|
||||
private HttpHeaders headers;
|
||||
|
||||
@Nullable
|
||||
private MultiValueMap<String, HttpCookie> cookies;
|
||||
|
||||
private Flux<DataBuffer> body = Flux.empty();
|
||||
|
||||
public FizzServerHttpRequestDecorator(ServerHttpRequest delegate) {
|
||||
super(delegate);
|
||||
headers = HttpHeaders.writableHttpHeaders(delegate.getHeaders());
|
||||
this.delegate = (AbstractServerHttpRequest) delegate;
|
||||
nativeRequest = this.delegate.getNativeRequest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiValueMap<String, String> getQueryParams() {
|
||||
if (queryParams == null) {
|
||||
queryParams = initQueryParams();
|
||||
}
|
||||
return queryParams;
|
||||
}
|
||||
|
||||
private MultiValueMap<String, String> initQueryParams() {
|
||||
MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<>();
|
||||
String query = getURI().getRawQuery();
|
||||
if (query != null) {
|
||||
Matcher matcher = QUERY_PATTERN.matcher(query);
|
||||
while (matcher.find()) {
|
||||
String name = decodeQueryParam(matcher.group(1));
|
||||
String eq = matcher.group(2);
|
||||
String value = matcher.group(3);
|
||||
value = (value != null ? decodeQueryParam(value) : (StringUtils.hasLength(eq) ? "" : null));
|
||||
queryParams.add(name, value);
|
||||
}
|
||||
}
|
||||
return queryParams;
|
||||
}
|
||||
|
||||
private String decodeQueryParam(String value) {
|
||||
try {
|
||||
return URLDecoder.decode(value, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return URLDecoder.decode(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpHeaders getHeaders() {
|
||||
if (headers == null) {
|
||||
headers = HttpHeaders.writableHttpHeaders(delegate.getHeaders());
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiValueMap<String, HttpCookie> getCookies() {
|
||||
if (cookies == null) {
|
||||
cookies = initCookies();
|
||||
}
|
||||
return cookies;
|
||||
}
|
||||
|
||||
private MultiValueMap<String, HttpCookie> initCookies() {
|
||||
MultiValueMap<String, HttpCookie> cookies = new LinkedMultiValueMap<>();
|
||||
for (CharSequence name : nativeRequest.cookies().keySet()) {
|
||||
for (Cookie cookie : nativeRequest.cookies().get(name)) {
|
||||
HttpCookie httpCookie = new HttpCookie(name.toString(), cookie.value());
|
||||
cookies.add(name.toString(), httpCookie);
|
||||
}
|
||||
}
|
||||
return cookies;
|
||||
}
|
||||
|
||||
public void setEmptyBody() {
|
||||
this.body = Flux.empty();
|
||||
}
|
||||
|
||||
@@ -5,12 +5,11 @@
|
||||
<parent>
|
||||
<artifactId>fizz-gateway-community</artifactId>
|
||||
<groupId>com.fizzgate</groupId>
|
||||
|
||||
<version>2.3.3-beta2</version>
|
||||
|
||||
<version>2.3.3-beta3</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>fizz-core</artifactId>
|
||||
|
||||
<properties>
|
||||
|
||||
@@ -5,12 +5,11 @@
|
||||
<parent>
|
||||
<artifactId>fizz-gateway-community</artifactId>
|
||||
<groupId>com.fizzgate</groupId>
|
||||
|
||||
<version>2.3.3-beta2</version>
|
||||
|
||||
<version>2.3.3-beta3</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>fizz-plugin</artifactId>
|
||||
|
||||
<properties>
|
||||
|
||||
@@ -5,12 +5,11 @@
|
||||
<parent>
|
||||
<artifactId>fizz-gateway-community</artifactId>
|
||||
<groupId>com.fizzgate</groupId>
|
||||
|
||||
<version>2.3.3-beta2</version>
|
||||
|
||||
<version>2.3.3-beta3</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>fizz-spring-boot-starter</artifactId>
|
||||
|
||||
<properties>
|
||||
|
||||
Reference in New Issue
Block a user