diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/cookie/Cookie.java b/httpclient5/src/main/java/org/apache/hc/client5/http/cookie/Cookie.java index 4a8ac10c7..e2ee347a0 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/cookie/Cookie.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/cookie/Cookie.java @@ -44,6 +44,7 @@ public interface Cookie { String MAX_AGE_ATTR = "max-age"; String SECURE_ATTR = "secure"; String EXPIRES_ATTR = "expires"; + String HTTP_ONLY_ATTR = "httpOnly"; /** * @since 5.0 @@ -126,5 +127,18 @@ public interface Cookie { */ Date getCreationDate(); + /** + * Checks whether this Cookie has been marked as {@code httpOnly}. + *
The default implementation returns {@code false}.
+ *
+ * @return true if this Cookie has been marked as {@code httpOnly},
+ * false otherwise
+ *
+ * @since 5.2
+ */
+ default boolean isHttpOnly(){
+ return false;
+ }
+
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/cookie/SetCookie.java b/httpclient5/src/main/java/org/apache/hc/client5/http/cookie/SetCookie.java
index 620006aae..546476ac9 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/cookie/SetCookie.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/cookie/SetCookie.java
@@ -85,5 +85,16 @@ public interface SetCookie extends Cookie {
*/
void setSecure (boolean secure);
+ /**
+ * Marks or unmarks this Cookie as {@code httpOnly}.
+ *
+ * @param httpOnly true if this cookie is to be marked as
+ * {@code httpOnly}, false otherwise
+ *
+ * @since 5.2
+ */
+ default void setHttpOnly (final boolean httpOnly){
+ }
+
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicClientCookie.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicClientCookie.java
index 62fb23348..e2cf88fd0 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicClientCookie.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicClientCookie.java
@@ -215,6 +215,19 @@ public final class BasicClientCookie implements SetCookie, Cloneable, Serializab
isSecure = secure;
}
+ /**
+ * Sets the http-only attribute of the cookie.
+ *
+ * @param httpOnly true if this cookie is to be marked as
+ * {@code httpOnly}, false otherwise
+ *
+ * @since 5.2
+ */
+ @Override
+ public void setHttpOnly(final boolean httpOnly) {
+ this.httpOnly = httpOnly;
+ }
+
/**
* Returns true if this cookie has expired.
* @param date Current time
@@ -236,6 +249,16 @@ public final class BasicClientCookie implements SetCookie, Cloneable, Serializab
return creationDate;
}
+ /**
+ * @return true if this Cookie has been marked as {@code httpOnly}, false otherwise
+ * @see #setHttpOnly(boolean)
+ * @since 5.2
+ */
+ @Override
+ public boolean isHttpOnly() {
+ return httpOnly;
+ }
+
/**
* @since 4.4
*/
@@ -317,5 +340,8 @@ public final class BasicClientCookie implements SetCookie, Cloneable, Serializab
private Date creationDate;
+ /** The {@code httpOnly} flag. */
+ private boolean httpOnly;
+
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicHttpOnlyHandler.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicHttpOnlyHandler.java
new file mode 100644
index 000000000..adb2067a7
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicHttpOnlyHandler.java
@@ -0,0 +1,71 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ *