diff --git a/commons-httpclient/src/main/java/net/lenni0451/commons/httpclient/utils/HttpRequestUtils.java b/commons-httpclient/src/main/java/net/lenni0451/commons/httpclient/utils/HttpRequestUtils.java
index 67f4c1c..ed23fc6 100644
--- a/commons-httpclient/src/main/java/net/lenni0451/commons/httpclient/utils/HttpRequestUtils.java
+++ b/commons-httpclient/src/main/java/net/lenni0451/commons/httpclient/utils/HttpRequestUtils.java
@@ -1,6 +1,7 @@
package net.lenni0451.commons.httpclient.utils;
import lombok.experimental.UtilityClass;
+import net.lenni0451.commons.httpclient.constants.Headers;
import javax.annotation.Nullable;
import javax.annotation.WillNotClose;
@@ -73,14 +74,28 @@ public static void updateCookies(@Nullable final CookieManager cookieManager, fi
}
/**
- * Set the headers for a connection.
+ * Set the headers for a connection.
+ * Cookies will be merged into one header separated by {@code ;}.
*
* @param connection The connection to set the headers for
* @param headers The headers to set
*/
public static void setHeaders(final HttpURLConnection connection, final Map> headers) {
for (Map.Entry> entry : headers.entrySet()) {
- connection.setRequestProperty(entry.getKey(), String.join("; ", entry.getValue()));
+ if (Headers.COOKIE.equalsIgnoreCase(entry.getKey())) {
+ connection.setRequestProperty(entry.getKey(), String.join("; ", entry.getValue()));
+ } else {
+ boolean first = true;
+ for (String val : entry.getValue()) {
+ if (first) {
+ first = false;
+ //Use the first value to clear all previous values
+ connection.setRequestProperty(entry.getKey(), val);
+ } else {
+ connection.addRequestProperty(entry.getKey(), val);
+ }
+ }
+ }
}
}