Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Update Apache HttpClient to version 5.x #372

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<htmlunitneko.version>2.52.0</htmlunitneko.version>
<htmlunitcorejs.version>2.52.0</htmlunitcorejs.version>

<httpcomponents.version>4.5.13</httpcomponents.version>
<httpcomponents.version>5.1</httpcomponents.version>
<jetty.version>9.4.43.v20210629</jetty.version>
<log4j.version>2.14.1</log4j.version>
<selenium.version>3.141.59</selenium.version>
Expand Down Expand Up @@ -1197,10 +1197,9 @@
</exclusion>
</exclusions>
</dependency>
<!-- this includes httpclient as depencency -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>${httpcomponents.version}</version>
</dependency>
<dependency>
Expand Down Expand Up @@ -1301,10 +1300,16 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpcomponents.version}</version>
<version>4.5.13</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
<scope>test</scope>
</dependency>

<!-- make our test for rendering svg images on canvas run -->
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/gargoylesoftware/htmlunit/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.http.client.utils.DateUtils;
import org.apache.hc.client5.http.utils.DateUtils;

import com.gargoylesoftware.css.dom.CSSStyleSheetImpl;
import com.gargoylesoftware.htmlunit.util.HeaderUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.cookie.CookieOrigin;
import org.apache.hc.client5.http.cookie.CookieOrigin;

import com.gargoylesoftware.htmlunit.httpclient.HtmlUnitBrowserCompatCookieSpec;
import com.gargoylesoftware.htmlunit.util.Cookie;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
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.CredentialsStore;
import org.apache.hc.client5.http.auth.NTCredentials;
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
import org.apache.hc.core5.http.protocol.HttpContext;

/**
* Default HtmlUnit implementation of the <tt>CredentialsProvider</tt> interface. Provides
Expand All @@ -38,7 +39,13 @@
* @author Ahmed Ashour
* @author Nicolas Belisle
*/
public class DefaultCredentialsProvider implements CredentialsProvider, Serializable {
public class DefaultCredentialsProvider implements CredentialsStore, Serializable {

public static final String ANY_PROTOCOL = null;
public static final String ANY_HOST = null;
public static final int ANY_PORT = -1;
public static final String ANY_REALM = null;
public static final String ANY_SCHEME = null;

private final Map<AuthScopeProxy, Credentials> credentialsMap_ = new HashMap<>();

Expand All @@ -51,8 +58,8 @@ public class DefaultCredentialsProvider implements CredentialsProvider, Serializ
* @param username the username for the new credentials
* @param password the password for the new credentials
*/
public void addCredentials(final String username, final String password) {
addCredentials(username, password, AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM);
public void addCredentials(final String username, final char[] password) {
addCredentials(username, password, ANY_HOST, ANY_PORT, ANY_REALM);
}

/**
Expand All @@ -65,9 +72,9 @@ public void addCredentials(final String username, final String password) {
* @param port the port to which to the new credentials apply (negative if applicable to any port)
* @param realm the realm to which to the new credentials apply ({@code null} if applicable to any realm)
*/
public void addCredentials(final String username, final String password, final String host,
public void addCredentials(final String username, final char[] password, final String host,
final int port, final String realm) {
final AuthScope authscope = new AuthScope(host, port, realm, AuthScope.ANY_SCHEME);
final AuthScope authscope = new AuthScope(ANY_PROTOCOL, host, port, realm, ANY_SCHEME);
final Credentials credentials = new UsernamePasswordCredentials(username, password);
setCredentials(authscope, credentials);
}
Expand All @@ -83,9 +90,9 @@ public void addCredentials(final String username, final String password, final S
* Essentially, the computer name for this machine.
* @param domain the domain to authenticate within
*/
public void addNTLMCredentials(final String username, final String password, final String host,
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, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME);
final AuthScope authscope = new AuthScope(ANY_PROTOCOL, host, port, ANY_REALM, ANY_SCHEME);
final Credentials credentials = new NTCredentials(username, password, workstation, domain);
setCredentials(authscope, credentials);
}
Expand Down Expand Up @@ -138,7 +145,7 @@ private static Credentials matchCredentials(final Map<AuthScopeProxy, Credential
* {@inheritDoc}
*/
@Override
public synchronized Credentials getCredentials(final AuthScope authscope) {
public synchronized Credentials getCredentials(final AuthScope authscope, final HttpContext httpContext) {
if (authscope == null) {
throw new IllegalArgumentException("Authentication scope may not be null");
}
Expand Down Expand Up @@ -199,18 +206,20 @@ public AuthScope getAuthScope() {
}

private void writeObject(final ObjectOutputStream stream) throws IOException {
stream.writeObject(authScope_.getProtocol());
stream.writeObject(authScope_.getHost());
stream.writeInt(authScope_.getPort());
stream.writeObject(authScope_.getRealm());
stream.writeObject(authScope_.getScheme());
stream.writeObject(authScope_.getSchemeName());
}

private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException {
final String protocol = (String) stream.readObject();
final String host = (String) stream.readObject();
final int port = stream.readInt();
final String realm = (String) stream.readObject();
final String scheme = (String) stream.readObject();
authScope_ = new AuthScope(host, port, realm, scheme);
authScope_ = new AuthScope(protocol, host, port, realm, scheme);
}

@Override
Expand Down
Loading