com.appland.appmap.reflect.HttpHeaders Maven / Gradle / Ivy
package com.appland.appmap.reflect;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
public interface HttpHeaders {
HttpHeaderDelegate getHeaderDelegate();
default String getHeader(String name) {
HttpHeaderDelegate delegate = getHeaderDelegate();
return delegate.fnGetHeader != null?
(String) delegate.invokeWrappedMethod(delegate.fnGetHeader, name)
: "";
}
@SuppressWarnings("unchecked")
default Enumeration getHeaderNames() {
HttpHeaderDelegate delegate = getHeaderDelegate();
try {
return (Enumeration) delegate.invokeWrappedMethod(delegate.fnGetHeaderNames);
} catch (ClassCastException _e) {
return Collections.enumeration((Collection)delegate.invokeWrappedMethod(delegate.fnGetHeaderNames));
} catch (Exception e) {
// Fall through
}
return Collections.enumeration(Collections.emptyList());
}
/**
* Non-standard utility method. Retrieves all headers.
*/
default Map getHeaders() {
HashMap headers = new HashMap<>();
for (Enumeration e = getHeaderNames(); e.hasMoreElements();) {
String headerName = (String) e.nextElement();
headers.put(headerName, this.getHeader(headerName));
}
return headers;
}
}