Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,17 @@ enum SpringWebHttpAttributesGetter

// since spring web 7.0
MethodHandle methodHandle =
findGetHeadersMethod(MethodType.methodType(List.class, String.class, List.class));
findGetHeadersMethod(MethodType.methodType(List.class, String.class));
if (methodHandle == null) {
// up to spring web 7.0
methodHandle =
findGetHeadersMethod(MethodType.methodType(Object.class, Object.class, Object.class));
methodHandle = findGetHeadersMethod(MethodType.methodType(List.class, Object.class));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be Object.class, Object.class

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
GET_HEADERS = methodHandle;
}

private static MethodHandle findGetHeadersMethod(MethodType methodType) {
try {
return MethodHandles.lookup().findVirtual(HttpHeaders.class, "getOrDefault", methodType);
return MethodHandles.lookup().findVirtual(HttpHeaders.class, "get", methodType);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be interesting to know why getOrDefault failed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I don't have an answer

} catch (Throwable t) {
return null;
}
Expand All @@ -98,7 +97,11 @@ public List<String> getHttpRequestHeader(HttpRequest httpRequest, String name) {
private static List<String> getHeader(HttpHeaders headers, String name) {
if (GET_HEADERS != null) {
try {
return (List<String>) GET_HEADERS.invoke(headers, name, emptyList());
List<String> result = (List<String>) GET_HEADERS.invoke(headers, name);
if (result == null) {
return emptyList();
}
return result;
} catch (Throwable t) {
// ignore
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@ class HeaderUtil {
static {
// since spring web 7.0
MethodHandle methodHandle =
findGetHeadersMethod(MethodType.methodType(List.class, String.class, List.class));
findGetHeadersMethod(MethodType.methodType(List.class, String.class));
if (methodHandle == null) {
// up to spring web 7.0
methodHandle =
findGetHeadersMethod(MethodType.methodType(Object.class, Object.class, Object.class));
methodHandle = findGetHeadersMethod(MethodType.methodType(List.class, Object.class));
}
GET_HEADERS = methodHandle;
}

private static MethodHandle findGetHeadersMethod(MethodType methodType) {
try {
return MethodHandles.lookup().findVirtual(HttpHeaders.class, "getOrDefault", methodType);
return MethodHandles.lookup().findVirtual(HttpHeaders.class, "get", methodType);
} catch (Throwable t) {
return null;
}
Expand All @@ -41,7 +40,11 @@ private static MethodHandle findGetHeadersMethod(MethodType methodType) {
static List<String> getHeader(HttpHeaders headers, String name) {
if (GET_HEADERS != null) {
try {
return (List<String>) GET_HEADERS.invoke(headers, name, emptyList());
List<String> result = (List<String>) GET_HEADERS.invoke(headers, name);
if (result == null) {
return emptyList();
}
return result;
} catch (Throwable t) {
// ignore
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,17 @@ public enum WebClientHttpAttributesGetter
static {
// since webflux 7.0
MethodHandle methodHandle =
findGetHeadersMethod(MethodType.methodType(List.class, String.class, List.class));
findGetHeadersMethod(MethodType.methodType(List.class, String.class));
if (methodHandle == null) {
// up to webflux 7.0
methodHandle =
findGetHeadersMethod(MethodType.methodType(Object.class, Object.class, Object.class));
methodHandle = findGetHeadersMethod(MethodType.methodType(List.class, Object.class));
}
GET_HEADERS = methodHandle;
}

private static MethodHandle findGetHeadersMethod(MethodType methodType) {
try {
return MethodHandles.lookup().findVirtual(HttpHeaders.class, "getOrDefault", methodType);
return MethodHandles.lookup().findVirtual(HttpHeaders.class, "get", methodType);
} catch (Throwable t) {
return null;
}
Expand All @@ -62,7 +61,11 @@ public String getHttpRequestMethod(ClientRequest request) {
public List<String> getHttpRequestHeader(ClientRequest request, String name) {
if (GET_HEADERS != null) {
try {
return (List<String>) GET_HEADERS.invoke(request.headers(), name, emptyList());
List<String> result = (List<String>) GET_HEADERS.invoke(request, name);
if (result == null) {
return emptyList();
}
return result;
} catch (Throwable t) {
// ignore
}
Expand Down
Loading