|
|
|
@ -18,11 +18,14 @@
|
|
|
|
|
|
|
|
|
|
package com.tencent.cloud.common.util.expresstion;
|
|
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
import io.netty.handler.codec.http.HttpHeaderNames;
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
|
|
|
|
|
import org.springframework.http.HttpCookie;
|
|
|
|
@ -110,6 +113,13 @@ public final class SpringWebExpressionLabelUtils {
|
|
|
|
|
}
|
|
|
|
|
labels.put(labelKey, getQueryValue(request, queryKey));
|
|
|
|
|
}
|
|
|
|
|
else if (ExpressionLabelUtils.isCookieLabel(labelKey)) {
|
|
|
|
|
String cookieKey = ExpressionLabelUtils.parseCookieKey(labelKey);
|
|
|
|
|
if (StringUtils.isBlank(cookieKey)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
labels.put(labelKey, getCookieValue(request, cookieKey));
|
|
|
|
|
}
|
|
|
|
|
else if (ExpressionLabelUtils.isMethodLabel(labelKey)) {
|
|
|
|
|
labels.put(labelKey, request.getMethodValue());
|
|
|
|
|
}
|
|
|
|
@ -158,4 +168,19 @@ public final class SpringWebExpressionLabelUtils {
|
|
|
|
|
String query = request.getURI().getQuery();
|
|
|
|
|
return ExpressionLabelUtils.getQueryValue(query, key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String getCookieValue(HttpRequest request, String key) {
|
|
|
|
|
String first = request.getHeaders().getFirst(HttpHeaders.COOKIE);
|
|
|
|
|
if (StringUtils.isEmpty(first)) {
|
|
|
|
|
return StringUtils.EMPTY;
|
|
|
|
|
}
|
|
|
|
|
String[] cookieArray = StringUtils.split(first,";");
|
|
|
|
|
for (String cookieItem : cookieArray) {
|
|
|
|
|
String[] cookieKv = StringUtils.split(cookieItem, "=");
|
|
|
|
|
if (cookieKv != null && cookieKv.length == 2 && StringUtils.equals(cookieKv[0], key)) {
|
|
|
|
|
return cookieKv[1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return StringUtils.EMPTY;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|