Skip to content
21 changes: 16 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
<htmlunitwebsocketclient.version>4.21.0</htmlunitwebsocketclient.version>
<htmlunitxpath.version>5.0.0-SNAPSHOT</htmlunitxpath.version>

<httpcomponents.version>4.5.14</httpcomponents.version>
<httpcomponents.core5.version>5.3.1</httpcomponents.core5.version>
<httpcomponents.client5.version>5.4.3</httpcomponents.client5.version>
<commons-lang3.version>3.20.0</commons-lang3.version>
<commons-io.version>2.21.0</commons-io.version>
<commons-logging.version>1.3.5</commons-logging.version>
Expand Down Expand Up @@ -1343,18 +1344,28 @@
</contributor>
</contributors>
<dependencies>
<!-- this includes httpclient as dependency -->
<!-- Apache HttpClient 5.x for HTTP/2 support -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>${httpcomponents.version}</version>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>${httpcomponents.client5.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.core5</groupId>
<artifactId>httpcore5</artifactId>
<version>${httpcomponents.core5.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.core5</groupId>
<artifactId>httpcore5-h2</artifactId>
<version>${httpcomponents.core5.version}</version>
</dependency>

<dependency>
<groupId>org.htmlunit</groupId>
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/htmlunit/DefaultCredentialsProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import java.util.HashMap;
import java.util.Map;

import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.NTCredentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.Credentials;
import org.apache.hc.client5.http.auth.CredentialsProvider;
import org.apache.hc.client5.http.auth.NTCredentials;
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
import org.htmlunit.httpclient.HtmlUnitUsernamePasswordCredentials;

/**
Expand Down Expand Up @@ -130,7 +130,7 @@ public void addCredentials(final String username, final char[] password, final S
public void addNTLMCredentials(final String username, final char[] password, final String host,
final int port, final String workstation, final String domain) {
final AuthScope authscope = new AuthScope(host, port, ANY_REALM, ANY_SCHEME);
final NTCredentials credentials = new NTCredentials(username, String.valueOf(password), workstation, domain);
final NTCredentials credentials = new NTCredentials(username, password, workstation, domain);
setCredentials(authscope, credentials);
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/htmlunit/WebClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.NoHttpResponseException;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.hc.client5.http.auth.CredentialsProvider;
import org.apache.hc.client5.http.cookie.MalformedCookieException;
import org.apache.hc.core5.http.NoHttpResponseException;
import org.htmlunit.attachment.Attachment;
import org.htmlunit.attachment.AttachmentHandler;
import org.htmlunit.csp.Policy;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/htmlunit/WebRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import java.util.Set;
import java.util.regex.Pattern;

import org.apache.http.auth.Credentials;
import org.apache.hc.client5.http.auth.Credentials;
import org.htmlunit.http.HttpUtils;
import org.htmlunit.httpclient.HtmlUnitUsernamePasswordCredentials;
import org.htmlunit.util.NameValuePair;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
package org.htmlunit.httpclient;

import org.apache.http.message.BasicHeaderValueFormatter;
import org.apache.hc.core5.http.message.BasicHeaderValueFormatter;

/**
* Customized BasicHeaderValueFormatter for HtmlUnit.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,29 @@
import java.util.Date;
import java.util.List;
import java.util.Locale;

import org.apache.http.FormattedHeader;
import org.apache.http.Header;
import org.apache.http.HeaderElement;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.utils.DateUtils;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookiePathComparator;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SM;
import org.apache.http.impl.cookie.BasicClientCookie;
import org.apache.http.impl.cookie.BasicCommentHandler;
import org.apache.http.impl.cookie.CookieSpecBase;
import org.apache.http.message.BasicHeader;
import org.apache.http.message.BasicHeaderElement;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.message.BufferedHeader;
import org.apache.http.message.ParserCursor;
import org.apache.http.message.TokenParser;
import org.apache.http.util.CharArrayBuffer;
import java.util.TimeZone;

import org.apache.hc.client5.http.cookie.Cookie;
import org.apache.hc.client5.http.cookie.CookieAttributeHandler;
import org.apache.hc.client5.http.cookie.CookieOrigin;
import org.apache.hc.client5.http.cookie.CookiePathComparator;
import org.apache.hc.client5.http.cookie.MalformedCookieException;
import org.apache.hc.client5.http.impl.cookie.BasicClientCookie;
import org.apache.hc.client5.http.impl.cookie.BasicCommentHandler;
import org.apache.hc.client5.http.impl.cookie.CookieSpecBase;
import org.apache.hc.core5.http.FormattedHeader;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HeaderElement;
import org.apache.hc.core5.http.HttpHeaders;
import org.apache.hc.core5.http.NameValuePair;
import org.apache.hc.core5.http.ParseException;
import org.apache.hc.core5.http.message.BasicHeader;
import org.apache.hc.core5.http.message.BasicHeaderElement;
import org.apache.hc.core5.http.message.BasicNameValuePair;
import org.apache.hc.core5.http.message.BufferedHeader;
import org.apache.hc.core5.http.message.ParserCursor;
import org.apache.hc.core5.http.message.TokenParser;
import org.apache.hc.core5.util.CharArrayBuffer;
import org.htmlunit.BrowserVersion;
import org.htmlunit.util.StringUtils;

Expand Down Expand Up @@ -89,7 +89,7 @@ public class HtmlUnitBrowserCompatCookieSpec extends CookieSpecBase {

static {
final Calendar calendar = Calendar.getInstance(Locale.ROOT);
calendar.setTimeZone(DateUtils.GMT);
calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
calendar.set(1970, Calendar.JANUARY, 1, 0, 0, 0);
calendar.set(Calendar.MILLISECOND, 0);
DATE_1_1_1970 = calendar.getTime();
Expand Down Expand Up @@ -140,7 +140,7 @@ else if (endPos == 0 || StringUtils.isBlank(text.substring(0, endPos))) {
}

final String headername = header.getName();
if (!SM.SET_COOKIE.equalsIgnoreCase(headername)) {
if (!HttpHeaders.SET_COOKIE.equalsIgnoreCase(headername)) {
throw new MalformedCookieException("Unrecognized cookie header '" + header + "'");
}
final HeaderElement[] helems = header.getElements();
Expand Down Expand Up @@ -221,7 +221,7 @@ public List<Header> formatCookies(final List<Cookie> cookies) {
cookies.sort(COOKIE_COMPARATOR);

final CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size());
buffer.append(SM.COOKIE);
buffer.append(HttpHeaders.COOKIE);
buffer.append(": ");
final int size = cookies.size();
for (int i = 0; i < size; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
*/
package org.htmlunit.httpclient;

import org.apache.http.cookie.CookieSpec;
import org.apache.http.cookie.CookieSpecProvider;
import org.apache.http.protocol.HttpContext;
import org.apache.hc.client5.http.cookie.CookieSpec;
import org.apache.hc.client5.http.cookie.CookieSpecFactory;
import org.apache.hc.core5.http.protocol.HttpContext;
import org.htmlunit.BrowserVersion;

/**
* Customized CookieSpecProvider for HtmlUnit.
* Customized CookieSpecFactory for HtmlUnit.
*
* @author Ronald Brill
*/
public final class HtmlUnitCookieSpecProvider implements CookieSpecProvider {
public final class HtmlUnitCookieSpecProvider implements CookieSpecFactory {

private final BrowserVersion browserVersion_;

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/htmlunit/httpclient/HtmlUnitCookieStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
package org.htmlunit.httpclient;

import java.io.Serializable;
import java.time.Instant;
import java.util.Date;
import java.util.List;

import org.apache.http.client.CookieStore;
import org.apache.http.cookie.ClientCookie;
import org.apache.http.cookie.Cookie;
import org.apache.hc.client5.http.cookie.Cookie;
import org.apache.hc.client5.http.cookie.CookieStore;
import org.htmlunit.CookieManager;

/**
* Implementation of {@link CookieStore} like {@link org.apache.http.impl.client.BasicCookieStore}
* Implementation of {@link CookieStore} like {@link org.apache.hc.client5.http.impl.cookie.BasicCookieStore}
* BUT using our own {@link CookieManager} as back end.
*
* @author Marc Guillemot
Expand All @@ -47,7 +47,7 @@
*/
@Override
public synchronized void addCookie(final Cookie cookie) {
manager_.addCookie(new HttpClientCookie((ClientCookie) cookie));
manager_.addCookie(new HttpClientCookie(cookie));
}

/**
Expand All @@ -62,8 +62,8 @@
* {@inheritDoc}
*/
@Override
public synchronized boolean clearExpired(final Date date) {
return manager_.clearExpired(date);
public synchronized boolean clearExpired(final Instant date) {

Check warning on line 65 in src/main/java/org/htmlunit/httpclient/HtmlUnitCookieStore.java

View workflow job for this annotation

GitHub Actions / PMD

[PMD] reported by reviewdog 🐶 Use block level locking rather than method level synchronization Raw Output: {"level":"warning","locations":[{"physicalLocation":{"artifactLocation":{"uri":"file:///home/runner/work/htmlunit/htmlunit/src/main/java/org/htmlunit/httpclient/HtmlUnitCookieStore.java"},"region":{"endColumn":45,"endLine":65,"startColumn":33,"startLine":65}}}],"message":{"text":"Use block level locking rather than method level synchronization"},"ruleId":"AvoidSynchronizedAtMethodLevel","ruleIndex":5}
return manager_.clearExpired(date != null ? Date.from(date) : null);
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/htmlunit/httpclient/HtmlUnitDomainHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
import java.net.UnknownHostException;
import java.util.Locale;

import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
import org.apache.http.impl.cookie.BasicDomainHandler;
import org.apache.http.util.Args;
import org.apache.http.util.TextUtils;
import org.apache.hc.client5.http.cookie.Cookie;
import org.apache.hc.client5.http.cookie.CookieOrigin;
import org.apache.hc.client5.http.cookie.MalformedCookieException;
import org.apache.hc.client5.http.cookie.SetCookie;
import org.apache.hc.client5.http.impl.cookie.BasicDomainHandler;
import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.TextUtils;
import org.htmlunit.BrowserVersion;
import org.htmlunit.HttpHeader;

Expand Down
17 changes: 10 additions & 7 deletions src/main/java/org/htmlunit/httpclient/HtmlUnitExpiresHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
import static org.htmlunit.BrowserVersionFeatures.HTTP_COOKIE_EXTENDED_DATE_PATTERNS_1;
import static org.htmlunit.BrowserVersionFeatures.HTTP_COOKIE_EXTENDED_DATE_PATTERNS_2;

import java.time.Instant;
import java.util.Date;

import org.apache.http.client.utils.DateUtils;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
import org.apache.http.impl.cookie.BasicExpiresHandler;
import org.apache.hc.client5.http.cookie.MalformedCookieException;
import org.apache.hc.client5.http.cookie.SetCookie;
import org.apache.hc.client5.http.impl.cookie.BasicExpiresHandler;
import org.apache.hc.client5.http.utils.DateUtils;
import org.htmlunit.BrowserVersion;

/**
Expand Down Expand Up @@ -91,11 +92,11 @@ public void parse(final SetCookie cookie, String value) throws MalformedCookieEx
}
value = value.replaceAll("[ ,:-]+", " ");

Date startDate = null;
Instant startDate = null;
String[] datePatterns = DEFAULT_DATE_PATTERNS;

if (null != browserVersion_) {
startDate = HtmlUnitBrowserCompatCookieSpec.DATE_1_1_1970;
startDate = HtmlUnitBrowserCompatCookieSpec.DATE_1_1_1970.toInstant();

if (browserVersion_.hasFeature(HTTP_COOKIE_EXTENDED_DATE_PATTERNS_1)) {
datePatterns = EXTENDED_DATE_PATTERNS_1;
Expand All @@ -107,6 +108,8 @@ public void parse(final SetCookie cookie, String value) throws MalformedCookieEx
}

final Date expiry = DateUtils.parseDate(value, datePatterns, startDate);
cookie.setExpiryDate(expiry);
if (expiry != null) {
cookie.setExpiryDate(expiry.toInstant());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
*/
package org.htmlunit.httpclient;

import org.apache.http.cookie.CommonCookieAttributeHandler;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
import org.apache.http.impl.cookie.BasicClientCookie;
import org.apache.hc.client5.http.cookie.CommonCookieAttributeHandler;
import org.apache.hc.client5.http.cookie.Cookie;
import org.apache.hc.client5.http.cookie.CookieOrigin;
import org.apache.hc.client5.http.cookie.MalformedCookieException;
import org.apache.hc.client5.http.cookie.SetCookie;
import org.apache.hc.client5.http.impl.cookie.BasicClientCookie;

/**
* Customized CookieAttributeHandler for handling of the httponly attribute.
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/htmlunit/httpclient/HtmlUnitMaxAgeHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
*/
package org.htmlunit.httpclient;

import java.util.Date;
import java.time.Instant;

import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
import org.apache.http.impl.cookie.BasicMaxAgeHandler;
import org.apache.http.util.Args;
import org.apache.hc.client5.http.cookie.MalformedCookieException;
import org.apache.hc.client5.http.cookie.SetCookie;
import org.apache.hc.client5.http.impl.cookie.BasicMaxAgeHandler;
import org.apache.hc.core5.util.Args;

/**
* Customized BasicMaxAgeHandler for HtmlUnit.
Expand All @@ -42,7 +42,7 @@ public void parse(final SetCookie cookie, final String value)
catch (final NumberFormatException e) {
throw new MalformedCookieException("Invalid 'max-age' attribute: " + value, e);
}
cookie.setExpiryDate(new Date(System.currentTimeMillis() + age * 1000L));
cookie.setExpiryDate(Instant.ofEpochMilli(System.currentTimeMillis() + age * 1000L));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
*/
package org.htmlunit.httpclient;

import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.impl.cookie.BasicPathHandler;
import org.apache.hc.client5.http.cookie.Cookie;
import org.apache.hc.client5.http.cookie.CookieOrigin;
import org.apache.hc.client5.http.cookie.MalformedCookieException;
import org.apache.hc.client5.http.impl.cookie.BasicPathHandler;

/**
* Customized BasicPathHandler for HtmlUnit.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
*/
package org.htmlunit.httpclient;

import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.ProtocolException;
import org.apache.http.impl.client.DefaultRedirectStrategy;
import org.apache.http.protocol.HttpContext;
import org.apache.hc.client5.http.impl.DefaultRedirectStrategy;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.ProtocolException;
import org.apache.hc.core5.http.protocol.HttpContext;

/**
* Customized DefaultRedirectStrategy for HtmlUnit.
Expand Down
Loading
Loading