This is an automated email from the ASF dual-hosted git repository.
likeguo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new a0003a6a01 [type: refactor] Compile Pattern in WebClientMessageWriter
(#5026)
a0003a6a01 is described below
commit a0003a6a01c5aae8cedf7e8cb71e39a815122cb2
Author: 吴伟杰 <[email protected]>
AuthorDate: Thu Aug 17 00:00:28 2023 +0800
[type: refactor] Compile Pattern in WebClientMessageWriter (#5026)
Co-authored-by: likeguo <[email protected]>
---
.../shenyu/plugin/response/strategy/WebClientMessageWriter.java | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git
a/shenyu-plugin/shenyu-plugin-response/src/main/java/org/apache/shenyu/plugin/response/strategy/WebClientMessageWriter.java
b/shenyu-plugin/shenyu-plugin-response/src/main/java/org/apache/shenyu/plugin/response/strategy/WebClientMessageWriter.java
index 2674d846c6..8ac2496e3a 100644
---
a/shenyu-plugin/shenyu-plugin-response/src/main/java/org/apache/shenyu/plugin/response/strategy/WebClientMessageWriter.java
+++
b/shenyu-plugin/shenyu-plugin-response/src/main/java/org/apache/shenyu/plugin/response/strategy/WebClientMessageWriter.java
@@ -40,6 +40,7 @@ import java.util.Optional;
import java.util.Set;
import java.util.StringJoiner;
import java.util.function.Consumer;
+import java.util.regex.Pattern;
/**
* The type Web client message writer.
@@ -49,7 +50,7 @@ public class WebClientMessageWriter implements MessageWriter {
/**
* the common binary media type regex.
*/
- private static final String COMMON_BIN_MEDIA_TYPE_REGEX;
+ private static final Pattern COMMON_BIN_MEDIA_TYPE_PATTERN;
/**
* the cross headers.
@@ -76,7 +77,7 @@ public class WebClientMessageWriter implements MessageWriter {
// image, pdf or stream does not do format processing.
if (clientResponse.headers().contentType().isPresent()) {
final String media =
clientResponse.headers().contentType().get().toString().toLowerCase();
- if (media.matches(COMMON_BIN_MEDIA_TYPE_REGEX)) {
+ if (COMMON_BIN_MEDIA_TYPE_PATTERN.matcher(media).matches()) {
return
response.writeWith(clientResponse.body(BodyExtractors.toDataBuffers()))
.doOnCancel(() -> clean(exchange));
}
@@ -167,6 +168,6 @@ public class WebClientMessageWriter implements
MessageWriter {
};
StringJoiner regexBuilder = new StringJoiner("|");
commonBinaryTypes.forEach(t ->
regexBuilder.add(String.format(".*%s.*", t)));
- COMMON_BIN_MEDIA_TYPE_REGEX = regexBuilder.toString();
+ COMMON_BIN_MEDIA_TYPE_PATTERN =
Pattern.compile(regexBuilder.toString());
}
}