Skip to content

Commit

Permalink
✨ feat: add unify functions for Request4j #4
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Jul 7, 2024
1 parent cb44365 commit 9576257
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions plugin/src/main/groovy/org/unify4j/common/Request4j.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<String, Object> getHeaders(HttpServletRequest request) {
Map<String, Object> headers = new HashMap<>();
Enumeration<String> 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.
Expand Down

0 comments on commit 9576257

Please sign in to comment.