diff --git a/plugin/src/main/groovy/org/unify4j/common/Request4j.java b/plugin/src/main/groovy/org/unify4j/common/Request4j.java index 62c4b91..96065bf 100644 --- a/plugin/src/main/groovy/org/unify4j/common/Request4j.java +++ b/plugin/src/main/groovy/org/unify4j/common/Request4j.java @@ -3,6 +3,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.servlet.http.HttpServletRequest; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; @@ -11,6 +12,7 @@ import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.Collections; +import java.util.Enumeration; import java.util.HashMap; import java.util.Map; @@ -100,6 +102,23 @@ public static boolean canConnect(String url) { } } + /** + * Retrieves all headers from the given HttpServletRequest and returns them as a Map. + * + * @param request The HttpServletRequest object containing the headers. + * @return A Map containing all the headers as key-value pairs. + */ + public static Map getHeaders(HttpServletRequest request) { + Map headers = new HashMap<>(); + Enumeration headerNames = request.getHeaderNames(); + while (headerNames.hasMoreElements()) { + String name = headerNames.nextElement(); + String value = request.getHeader(name); + headers.put(name, value); + } + return headers; + } + /** * Parses query parameters from the given query string and returns them as a map. * This function takes a query string and extracts key-value pairs representing query parameters.