diff --git a/client/pom.xml b/client/pom.xml
index 31d5153b27..f563cde683 100644
--- a/client/pom.xml
+++ b/client/pom.xml
@@ -59,5 +59,9 @@
javassist
3.21.0-GA
+
+ javax.servlet
+ javax.servlet-api
+
diff --git a/client/src/main/java/org/asynchttpclient/RequestBuilderBase.java b/client/src/main/java/org/asynchttpclient/RequestBuilderBase.java
index 0beba8b256..8f8b281a19 100644
--- a/client/src/main/java/org/asynchttpclient/RequestBuilderBase.java
+++ b/client/src/main/java/org/asynchttpclient/RequestBuilderBase.java
@@ -15,13 +15,22 @@
*/
package org.asynchttpclient;
-import static org.asynchttpclient.util.HttpUtils.*;
-import static org.asynchttpclient.util.MiscUtils.isNonEmpty;
import io.netty.handler.codec.http.DefaultHttpHeaders;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.resolver.DefaultNameResolver;
import io.netty.resolver.NameResolver;
import io.netty.util.concurrent.ImmediateEventExecutor;
+import org.asynchttpclient.channel.ChannelPoolPartitioning;
+import org.asynchttpclient.cookie.Cookie;
+import org.asynchttpclient.proxy.ProxyServer;
+import org.asynchttpclient.request.body.generator.BodyGenerator;
+import org.asynchttpclient.request.body.generator.ReactiveStreamsBodyGenerator;
+import org.asynchttpclient.request.body.multipart.Part;
+import org.asynchttpclient.uri.Uri;
+import org.asynchttpclient.util.UriEncoder;
+import org.reactivestreams.Publisher;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.InputStream;
@@ -34,17 +43,9 @@
import java.util.List;
import java.util.Map;
-import org.asynchttpclient.channel.ChannelPoolPartitioning;
-import org.asynchttpclient.cookie.Cookie;
-import org.asynchttpclient.proxy.ProxyServer;
-import org.asynchttpclient.request.body.generator.BodyGenerator;
-import org.asynchttpclient.request.body.generator.ReactiveStreamsBodyGenerator;
-import org.asynchttpclient.request.body.multipart.Part;
-import org.asynchttpclient.uri.Uri;
-import org.asynchttpclient.util.UriEncoder;
-import org.reactivestreams.Publisher;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import static org.asynchttpclient.util.HttpUtils.parseCharset;
+import static org.asynchttpclient.util.HttpUtils.validateSupportedScheme;
+import static org.asynchttpclient.util.MiscUtils.isNonEmpty;
/**
* Builder for {@link Request}
@@ -194,14 +195,17 @@ public T setHeaders(HttpHeaders headers) {
public T setHeaders(Map> headers) {
this.headers.clear();
if (headers != null) {
- for (Map.Entry> entry : headers.entrySet()) {
- String headerName = entry.getKey();
- this.headers.add(headerName, entry.getValue());
- }
+ headers.forEach((name, values) -> this.headers.add(name, values));
}
return asDerivedType();
}
+ public T setSingleHeaders(Map headers) {
+ this.headers.clear();
+ headers.forEach((name, value) -> this.headers.add(name, value));
+ return asDerivedType();
+ }
+
private void lazyInitCookies() {
if (this.cookies == null)
this.cookies = new ArrayList<>(3);
diff --git a/client/src/main/java/org/asynchttpclient/cookie/Cookie.java b/client/src/main/java/org/asynchttpclient/cookie/Cookie.java
index b08e9de2b2..987af4d165 100644
--- a/client/src/main/java/org/asynchttpclient/cookie/Cookie.java
+++ b/client/src/main/java/org/asynchttpclient/cookie/Cookie.java
@@ -12,16 +12,65 @@
*/
package org.asynchttpclient.cookie;
-import static org.asynchttpclient.cookie.CookieUtil.*;
+import static org.asynchttpclient.cookie.CookieUtil.validateCookieAttribute;
+import static org.asynchttpclient.cookie.CookieUtil.validateCookieName;
+import static org.asynchttpclient.cookie.CookieUtil.validateCookieValue;
public class Cookie {
+ /**
+ * Method to get a {@link org.asynchttpclient.cookie.Cookie} from {@code javax.servlet} package's {@link javax.servlet.http.Cookie}
+ *
+ * @param cookie base entity to convert
+ * @param wrap true if the value of this {@link Cookie} is to be wrapped with double quotes.
+ * @return converted {@link Cookie}
+ */
+ public static Cookie newCookie(javax.servlet.http.Cookie cookie, boolean wrap) {
+ return new Cookie(cookie.getName(), cookie.getValue(), wrap, cookie.getDomain(), cookie.getPath(), cookie.getMaxAge(), cookie.getSecure(), cookie.isHttpOnly());
+ }
+
+ /**
+ * Method to get a valid {@link org.asynchttpclient.cookie.Cookie} from {@code javax.servlet} package's {@link javax.servlet.http.Cookie}
+ *
+ * @param cookie base entity to convert
+ * @param wrap true if the value of this {@link Cookie} is to be wrapped with double quotes.
+ * @return converted {@link Cookie}
+ * @throws IllegalArgumentException if any part of {@code cookie} is invalid
+ */
+ public static Cookie newValidCookie(javax.servlet.http.Cookie cookie, boolean wrap) {
+ return new Cookie(validateCookieName(cookie.getName()), validateCookieValue(cookie.getValue()), wrap, validateCookieAttribute("domain", cookie.getDomain()), validateCookieAttribute("path", cookie.getPath()), cookie.getMaxAge(), cookie.getSecure(), cookie.isHttpOnly());
+ }
+
+ /**
+ * Method to get a {@link org.asynchttpclient.cookie.Cookie} from Netty's {@link io.netty.handler.codec.http.cookie.Cookie}
+ *
+ * @param cookie base entity to convert
+ * @return converted {@link Cookie}
+ */
+ public static Cookie newCookie(io.netty.handler.codec.http.cookie.Cookie cookie) {
+ return new Cookie(cookie.name(), cookie.value(), cookie.wrap(), cookie.domain(), cookie.path(), cookie.maxAge(), cookie.isSecure(), cookie.isHttpOnly());
+ }
+
+ /**
+ * Method to get a valid {@link org.asynchttpclient.cookie.Cookie} from Netty's {@link io.netty.handler.codec.http.cookie.Cookie}
+ *
+ * @param cookie base entity to convert
+ * @return converted {@link Cookie}
+ * @throws IllegalArgumentException if any part of {@code cookie} is invalid
+ */
+ public static Cookie newValidCookie(io.netty.handler.codec.http.cookie.Cookie cookie) {
+ return new Cookie(validateCookieName(cookie.name()), validateCookieValue(cookie.value()), cookie.wrap(), validateCookieAttribute("domain", cookie.domain()), validateCookieAttribute("path", cookie.path()), cookie.maxAge(), cookie.isSecure(), cookie.isHttpOnly());
+ }
+
public static Cookie newValidCookie(String name, String value, boolean wrap, String domain, String path, long maxAge, boolean secure, boolean httpOnly) {
return new Cookie(validateCookieName(name), validateCookieValue(value), wrap, validateCookieAttribute("domain", domain), validateCookieAttribute("path", path), maxAge, secure, httpOnly);
}
private final String name;
private final String value;
+ /**
+ * If value should be wrapped with double quotes during serialization
+ */
private final boolean wrap;
private final String domain;
private final String path;
@@ -52,6 +101,9 @@ public String getValue() {
return value;
}
+ /**
+ * @return true if the value of this {@link Cookie} is to be wrapped with double quotes.
+ */
public boolean isWrap() {
return wrap;
}
diff --git a/pom.xml b/pom.xml
index edead3b84a..d4aa96b0dd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -251,6 +251,12 @@
${netty.version}
true
+
+ javax.servlet
+ javax.servlet-api
+ ${javax.servlet-api.version}
+ true
+
@@ -375,6 +381,7 @@
1.8
1.8
4.0.42.Final
+ 3.1.0
1.7.21
1.1.7
6.9.10