You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2017/09/02 15:28:15 UTC
[15/17] httpcomponents-client git commit: Moved classes and renamed
packages (no functional changes)
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/main/java/org/apache/hc/client5/http/classic/ExecChainHandler.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/ExecChainHandler.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/ExecChainHandler.java
new file mode 100644
index 0000000..b4f1a61
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/ExecChainHandler.java
@@ -0,0 +1,56 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.classic;
+
+import java.io.IOException;
+
+import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.HttpException;
+
+/**
+ * This interface represents an element in the HTTP request execution chain. Each element can
+ * either be a decorator around another element that implements a cross cutting aspect or
+ * a self-contained executor capable of producing a response for the given request.
+ * <p>
+ * Important: please note it is required for decorators that implement post execution aspects
+ * or response post-processing of any sort to release resources associated with the response
+ * by calling {@link ClassicHttpResponse#close()} methods in case of an I/O, protocol or
+ * runtime exception, or in case the response is not propagated to the caller.
+ * </p>
+ *
+ * @since 4.3
+ */
+public interface ExecChainHandler {
+
+ ClassicHttpResponse execute(
+ ClassicHttpRequest request,
+ ExecChain.Scope scope,
+ ExecChain chain) throws IOException, HttpException;
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/main/java/org/apache/hc/client5/http/classic/ExecRuntime.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/ExecRuntime.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/ExecRuntime.java
new file mode 100644
index 0000000..8faed9e
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/ExecRuntime.java
@@ -0,0 +1,87 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.classic;
+
+import java.io.IOException;
+
+import org.apache.hc.client5.http.HttpRoute;
+import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.core5.annotation.Internal;
+import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.util.TimeValue;
+
+/**
+ * Execution runtime that provides access to the underlying connection endpoint and helps
+ * manager its life cycle.
+ * <p>
+ * This interface is considered internal and generally ought not be used or accessed
+ * by custom request exec handlers.
+ *
+ * @since 5.0
+ */
+@Internal
+public interface ExecRuntime {
+
+ boolean isExecutionAborted();
+
+ boolean isConnectionAcquired();
+
+ void acquireConnection(
+ HttpRoute route,
+ Object state,
+ HttpClientContext context) throws IOException;
+
+ void releaseConnection();
+
+ void discardConnection();
+
+ boolean isConnected();
+
+ void disconnect() throws IOException;
+
+ void connect(HttpClientContext context) throws IOException;
+
+ void upgradeTls(HttpClientContext context) throws IOException;
+
+ ClassicHttpResponse execute(
+ ClassicHttpRequest request,
+ HttpClientContext context) throws IOException, HttpException;
+
+ boolean isConnectionReusable();
+
+ void markConnectionReusable();
+
+ void markConnectionNonReusable();
+
+ void setConnectionState(Object state);
+
+ void setConnectionValidFor(TimeValue duration);
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/main/java/org/apache/hc/client5/http/classic/HttpClient.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/HttpClient.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/HttpClient.java
new file mode 100644
index 0000000..a63818b
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/HttpClient.java
@@ -0,0 +1,209 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.classic;
+
+import java.io.IOException;
+
+import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.io.HttpClientResponseHandler;
+import org.apache.hc.core5.http.protocol.HttpContext;
+
+/**
+ * This interface represents only the most basic contract for HTTP request
+ * execution. It imposes no restrictions or particular details on the request
+ * execution process and leaves the specifics of state management,
+ * authentication and redirect handling up to individual implementations.
+ *
+ * @since 4.0
+ */
+public interface HttpClient {
+
+ /**
+ * Executes HTTP request using the default context.
+ *
+ * @param request the request to execute
+ *
+ * @return the response to the request. This is always a final response,
+ * never an intermediate response with an 1xx status code.
+ * Whether redirects or authentication challenges will be returned
+ * or handled automatically depends on the implementation and
+ * configuration of this client.
+ * @throws IOException in case of a problem or the connection was aborted
+ */
+ HttpResponse execute(ClassicHttpRequest request) throws IOException;
+
+ /**
+ * Executes HTTP request using the given context.
+ *
+ * @param request the request to execute
+ * @param context the context to use for the execution, or
+ * {@code null} to use the default context
+ *
+ * @return the response to the request. This is always a final response,
+ * never an intermediate response with an 1xx status code.
+ * Whether redirects or authentication challenges will be returned
+ * or handled automatically depends on the implementation and
+ * configuration of this client.
+ * @throws IOException in case of a problem or the connection was aborted
+ */
+ HttpResponse execute(ClassicHttpRequest request, HttpContext context) throws IOException;
+
+ /**
+ * Executes HTTP request using the default context.
+ *
+ * @param target the target host for the request.
+ * Implementations may accept {@code null}
+ * if they can still determine a route, for example
+ * to a default target or by inspecting the request.
+ * @param request the request to execute
+ *
+ * @return the response to the request. This is always a final response,
+ * never an intermediate response with an 1xx status code.
+ * Whether redirects or authentication challenges will be returned
+ * or handled automatically depends on the implementation and
+ * configuration of this client.
+ * @throws IOException in case of a problem or the connection was aborted
+ */
+ ClassicHttpResponse execute(HttpHost target, ClassicHttpRequest request) throws IOException;
+
+ /**
+ * Executes HTTP request using the given context.
+ *
+ * @param target the target host for the request.
+ * Implementations may accept {@code null}
+ * if they can still determine a route, for example
+ * to a default target or by inspecting the request.
+ * @param request the request to execute
+ * @param context the context to use for the execution, or
+ * {@code null} to use the default context
+ *
+ * @return the response to the request. This is always a final response,
+ * never an intermediate response with an 1xx status code.
+ * Whether redirects or authentication challenges will be returned
+ * or handled automatically depends on the implementation and
+ * configuration of this client.
+ * @throws IOException in case of a problem or the connection was aborted
+ */
+ HttpResponse execute(HttpHost target, ClassicHttpRequest request, HttpContext context) throws IOException;
+
+ /**
+ * Executes HTTP request using the default context and processes the
+ * response using the given response handler.
+ * <p>
+ * Implementing classes are required to ensure that the content entity
+ * associated with the response is fully consumed and the underlying
+ * connection is released back to the connection manager automatically
+ * in all cases relieving individual {@link HttpClientResponseHandler}s from
+ * having to manage resource deallocation internally.
+ * </p>
+ *
+ * @param request the request to execute
+ * @param HttpClientResponseHandler the response handler
+ *
+ * @return the response object as generated by the response handler.
+ * @throws IOException in case of a problem or the connection was aborted
+ */
+ <T> T execute(ClassicHttpRequest request, HttpClientResponseHandler<? extends T> HttpClientResponseHandler) throws IOException;
+
+ /**
+ * Executes HTTP request using the given context and processes the
+ * response using the given response handler.
+ * <p>
+ * Implementing classes are required to ensure that the content entity
+ * associated with the response is fully consumed and the underlying
+ * connection is released back to the connection manager automatically
+ * in all cases relieving individual {@link HttpClientResponseHandler}s from
+ * having to manage resource deallocation internally.
+ * </p>
+ *
+ * @param request the request to execute
+ * @param HttpClientResponseHandler the response handler
+ * @param context the context to use for the execution, or
+ * {@code null} to use the default context
+ *
+ * @return the response object as generated by the response handler.
+ * @throws IOException in case of a problem or the connection was aborted
+ */
+ <T> T execute(ClassicHttpRequest request, HttpClientResponseHandler<? extends T> HttpClientResponseHandler, HttpContext context) throws IOException;
+
+ /**
+ * Executes HTTP request to the target using the default context and
+ * processes the response using the given response handler.
+ * <p>
+ * Implementing classes are required to ensure that the content entity
+ * associated with the response is fully consumed and the underlying
+ * connection is released back to the connection manager automatically
+ * in all cases relieving individual {@link HttpClientResponseHandler}s from
+ * having to manage resource deallocation internally.
+ * </p>
+ *
+ * @param target the target host for the request.
+ * Implementations may accept {@code null}
+ * if they can still determine a route, for example
+ * to a default target or by inspecting the request.
+ * @param request the request to execute
+ * @param HttpClientResponseHandler the response handler
+ *
+ * @return the response object as generated by the response handler.
+ * @throws IOException in case of a problem or the connection was aborted
+ */
+ <T> T execute(HttpHost target, ClassicHttpRequest request, HttpClientResponseHandler<? extends T> HttpClientResponseHandler) throws IOException;
+
+ /**
+ * Executes HTTP request to the target using the given context and
+ * processes the response using the given response handler.
+ * <p>
+ * Implementing classes are required to ensure that the content entity
+ * associated with the response is fully consumed and the underlying
+ * connection is released back to the connection manager automatically
+ * in all cases relieving individual {@link HttpClientResponseHandler}s from
+ * having to manage resource deallocation internally.
+ * </p>
+ *
+ * @param target the target host for the request.
+ * Implementations may accept {@code null}
+ * if they can still determine a route, for example
+ * to a default target or by inspecting the request.
+ * @param request the request to execute
+ * @param HttpClientResponseHandler the response handler
+ * @param context the context to use for the execution, or
+ * {@code null} to use the default context
+ *
+ * @return the response object as generated by the response handler.
+ * @throws IOException in case of a problem or the connection was aborted
+ */
+ <T> T execute(
+ HttpHost target,
+ ClassicHttpRequest request,
+ HttpClientResponseHandler<? extends T> HttpClientResponseHandler,
+ HttpContext context) throws IOException;
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpDelete.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpDelete.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpDelete.java
new file mode 100644
index 0000000..916b8bb
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpDelete.java
@@ -0,0 +1,65 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.classic.methods;
+
+import java.net.URI;
+
+/**
+ * HTTP DELETE method
+ * <p>
+ * The HTTP DELETE method is defined in section 9.7 of
+ * <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>:
+ * <blockquote>
+ * The DELETE method requests that the origin server delete the resource
+ * identified by the Request-URI. [...] The client cannot
+ * be guaranteed that the operation has been carried out, even if the
+ * status code returned from the origin server indicates that the action
+ * has been completed successfully.
+ * </blockquote>
+ *
+ * @since 4.0
+ */
+public class HttpDelete extends HttpUriRequestBase {
+
+ private static final long serialVersionUID = 1L;
+
+ public final static String METHOD_NAME = "DELETE";
+
+
+ public HttpDelete(final URI uri) {
+ super(METHOD_NAME, uri);
+ }
+
+ /**
+ * @throws IllegalArgumentException if the uri is invalid.
+ */
+ public HttpDelete(final String uri) {
+ this(URI.create(uri));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpExecutionAware.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpExecutionAware.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpExecutionAware.java
new file mode 100644
index 0000000..f6a6700
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpExecutionAware.java
@@ -0,0 +1,48 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.classic.methods;
+
+import org.apache.hc.core5.concurrent.Cancellable;
+
+/**
+ * Interface to be implemented by any object that wishes to be notified of
+ * blocking I/O operations that could be cancelled.
+ *
+ * @since 4.3
+ */
+public interface HttpExecutionAware {
+
+ boolean isAborted();
+
+ /**
+ * Sets {@link Cancellable} for the ongoing operation.
+ */
+ void setCancellable(Cancellable cancellable);
+
+}
+
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpGet.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpGet.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpGet.java
new file mode 100644
index 0000000..ab7f8bb
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpGet.java
@@ -0,0 +1,65 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.classic.methods;
+
+import java.net.URI;
+
+/**
+ * HTTP GET method.
+ * <p>
+ * The HTTP GET method is defined in section 9.3 of
+ * <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>:
+ * </p>
+ * <blockquote>
+ * The GET method means retrieve whatever information (in the form of an
+ * entity) is identified by the Request-URI. If the Request-URI refers
+ * to a data-producing process, it is the produced data which shall be
+ * returned as the entity in the response and not the source text of the
+ * process, unless that text happens to be the output of the process.
+ * </blockquote>
+ *
+ * @since 4.0
+ */
+public class HttpGet extends HttpUriRequestBase {
+
+ private static final long serialVersionUID = 1L;
+
+ public final static String METHOD_NAME = "GET";
+
+ public HttpGet(final URI uri) {
+ super(METHOD_NAME, uri);
+ }
+
+ /**
+ * @throws IllegalArgumentException if the uri is invalid.
+ */
+ public HttpGet(final String uri) {
+ this(URI.create(uri));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpHead.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpHead.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpHead.java
new file mode 100644
index 0000000..57ee9f6
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpHead.java
@@ -0,0 +1,68 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.classic.methods;
+
+import java.net.URI;
+
+/**
+ * HTTP HEAD method.
+ * <p>
+ * The HTTP HEAD method is defined in section 9.4 of
+ * <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>:
+ * </p>
+ * <blockquote>
+ * The HEAD method is identical to GET except that the server MUST NOT
+ * return a message-body in the response. The metainformation contained
+ * in the HTTP headers in response to a HEAD request SHOULD be identical
+ * to the information sent in response to a GET request. This method can
+ * be used for obtaining metainformation about the entity implied by the
+ * request without transferring the entity-body itself. This method is
+ * often used for testing hypertext links for validity, accessibility,
+ * and recent modification.
+ * </blockquote>
+ *
+ * @since 4.0
+ */
+public class HttpHead extends HttpUriRequestBase {
+
+ private static final long serialVersionUID = 1L;
+
+ public final static String METHOD_NAME = "HEAD";
+
+ public HttpHead(final URI uri) {
+ super(METHOD_NAME, uri);
+ }
+
+ /**
+ * @throws IllegalArgumentException if the uri is invalid.
+ */
+ public HttpHead(final String uri) {
+ this(URI.create(uri));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpOptions.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpOptions.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpOptions.java
new file mode 100644
index 0000000..a74deb5
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpOptions.java
@@ -0,0 +1,91 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.classic.methods;
+
+import java.net.URI;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.hc.core5.http.HeaderElement;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.message.MessageSupport;
+import org.apache.hc.core5.util.Args;
+
+/**
+ * HTTP OPTIONS method.
+ * <p>
+ * The HTTP OPTIONS method is defined in section 9.2 of
+ * <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>:
+ * </p>
+ * <blockquote>
+ * The OPTIONS method represents a request for information about the
+ * communication options available on the request/response chain
+ * identified by the Request-URI. This method allows the client to
+ * determine the options and/or requirements associated with a resource,
+ * or the capabilities of a server, without implying a resource action
+ * or initiating a resource retrieval.
+ * </blockquote>
+ *
+ * @since 4.0
+ */
+public class HttpOptions extends HttpUriRequestBase {
+
+ private static final long serialVersionUID = 1L;
+
+ public final static String METHOD_NAME = "OPTIONS";
+
+ public HttpOptions(final URI uri) {
+ super(METHOD_NAME, uri);
+ }
+
+ /**
+ * @throws IllegalArgumentException if the uri is invalid.
+ */
+ public HttpOptions(final String uri) {
+ this(URI.create(uri));
+ }
+
+ @Override
+ public String getMethod() {
+ return METHOD_NAME;
+ }
+
+ public Set<String> getAllowedMethods(final HttpResponse response) {
+ Args.notNull(response, "HTTP response");
+
+ final Iterator<HeaderElement> it = MessageSupport.iterate(response, "Allow");
+ final Set<String> methods = new HashSet<>();
+ while (it.hasNext()) {
+ final HeaderElement element = it.next();
+ methods.add(element.getName());
+ }
+ return methods;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPatch.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPatch.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPatch.java
new file mode 100644
index 0000000..5cbe3b2
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPatch.java
@@ -0,0 +1,65 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.classic.methods;
+
+import java.net.URI;
+
+/**
+ * HTTP PATCH method.
+ * <p>
+ * The HTTP PATCH method is defined in <a
+ * href="http://tools.ietf.org/html/rfc5789">RF5789</a>:
+ * </p>
+ * <blockquote> The PATCH
+ * method requests that a set of changes described in the request entity be
+ * applied to the resource identified by the Request- URI. Differs from the PUT
+ * method in the way the server processes the enclosed entity to modify the
+ * resource identified by the Request-URI. In a PUT request, the enclosed entity
+ * origin server, and the client is requesting that the stored version be
+ * replaced. With PATCH, however, the enclosed entity contains a set of
+ * instructions describing how a resource currently residing on the origin
+ * server should be modified to produce a new version.
+ * </blockquote>
+ *
+ * @since 4.2
+ */
+public class HttpPatch extends HttpUriRequestBase {
+
+ private static final long serialVersionUID = 1L;
+
+ public final static String METHOD_NAME = "PATCH";
+
+ public HttpPatch(final URI uri) {
+ super(METHOD_NAME, uri);
+ }
+
+ public HttpPatch(final String uri) {
+ this(URI.create(uri));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPost.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPost.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPost.java
new file mode 100644
index 0000000..7a8fbd2
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPost.java
@@ -0,0 +1,72 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.classic.methods;
+
+import java.net.URI;
+
+/**
+ * HTTP POST method.
+ * <p>
+ * The HTTP POST method is defined in section 9.5 of
+ * <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>:
+ * </p>
+ * <blockquote>
+ * The POST method is used to request that the origin server accept the entity
+ * enclosed in the request as a new subordinate of the resource identified by
+ * the Request-URI in the Request-Line. POST is designed to allow a uniform
+ * method to cover the following functions:
+ * <ul>
+ * <li>Annotation of existing resources</li>
+ * <li>Posting a message to a bulletin board, newsgroup, mailing list, or
+ * similar group of articles</li>
+ * <li>Providing a block of data, such as the result of submitting a form,
+ * to a data-handling process</li>
+ * <li>Extending a database through an append operation</li>
+ * </ul>
+ * </blockquote>
+ *
+ * @since 4.0
+ */
+public class HttpPost extends HttpUriRequestBase {
+
+ private static final long serialVersionUID = 1L;
+
+ public final static String METHOD_NAME = "POST";
+
+ public HttpPost(final URI uri) {
+ super(METHOD_NAME, uri);
+ }
+
+ /**
+ * @throws IllegalArgumentException if the uri is invalid.
+ */
+ public HttpPost(final String uri) {
+ this(URI.create(uri));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPut.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPut.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPut.java
new file mode 100644
index 0000000..476da12
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPut.java
@@ -0,0 +1,63 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.classic.methods;
+
+import java.net.URI;
+
+/**
+ * HTTP PUT method.
+ * <p>
+ * The HTTP PUT method is defined in section 9.6 of
+ * <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>:
+ * </p>
+ * <blockquote>
+ * The PUT method requests that the enclosed entity be stored under the
+ * supplied Request-URI. If the Request-URI refers to an already
+ * existing resource, the enclosed entity SHOULD be considered as a
+ * modified version of the one residing on the origin server.
+ * </blockquote>
+ *
+ * @since 4.0
+ */
+public class HttpPut extends HttpUriRequestBase {
+
+ private static final long serialVersionUID = 1L;
+ public final static String METHOD_NAME = "PUT";
+
+ public HttpPut(final URI uri) {
+ super(METHOD_NAME, uri);
+ }
+
+ /**
+ * @throws IllegalArgumentException if the uri is invalid.
+ */
+ public HttpPut(final String uri) {
+ this(URI.create(uri));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpTrace.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpTrace.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpTrace.java
new file mode 100644
index 0000000..ada666f
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpTrace.java
@@ -0,0 +1,67 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.classic.methods;
+
+import java.net.URI;
+
+/**
+ * HTTP TRACE method.
+ * <p>
+ * The HTTP TRACE method is defined in section 9.6 of
+ * <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>:
+ * </p>
+ * <blockquote>
+ * The TRACE method is used to invoke a remote, application-layer loop-
+ * back of the request message. The final recipient of the request
+ * SHOULD reflect the message received back to the client as the
+ * entity-body of a 200 (OK) response. The final recipient is either the
+ * origin server or the first proxy or gateway to receive a Max-Forwards
+ * value of zero (0) in the request (see section 14.31). A TRACE request
+ * MUST NOT include an entity.
+ * </blockquote>
+ *
+ * @since 4.0
+ */
+public class HttpTrace extends HttpUriRequestBase {
+
+ private static final long serialVersionUID = 1L;
+
+ public final static String METHOD_NAME = "TRACE";
+
+ public HttpTrace(final URI uri) {
+ super(METHOD_NAME, uri);
+ }
+
+ /**
+ * @throws IllegalArgumentException if the uri is invalid.
+ */
+ public HttpTrace(final String uri) {
+ this(URI.create(uri));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpUriRequest.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpUriRequest.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpUriRequest.java
new file mode 100644
index 0000000..1c3064b
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpUriRequest.java
@@ -0,0 +1,57 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.classic.methods;
+
+import org.apache.hc.core5.http.ClassicHttpRequest;
+
+/**
+ * Extended version of the {@link ClassicHttpRequest} interface that provides
+ * convenience methods to access request properties such as request URI
+ * and method type.
+ *
+ * @since 4.0
+ */
+public interface HttpUriRequest extends ClassicHttpRequest {
+
+ /**
+ * Aborts execution of the request.
+ *
+ * @throws UnsupportedOperationException if the abort operation
+ * is not supported / cannot be implemented.
+ */
+ void abort() throws UnsupportedOperationException;
+
+ /**
+ * Tests if the request execution has been aborted.
+ *
+ * @return {@code true} if the request execution has been aborted,
+ * {@code false} otherwise.
+ */
+ boolean isAborted();
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpUriRequestBase.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpUriRequestBase.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpUriRequestBase.java
new file mode 100644
index 0000000..bcc8bfc
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpUriRequestBase.java
@@ -0,0 +1,110 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.client5.http.classic.methods;
+
+import java.net.URI;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.hc.client5.http.CancellableAware;
+import org.apache.hc.client5.http.config.Configurable;
+import org.apache.hc.client5.http.config.RequestConfig;
+import org.apache.hc.core5.concurrent.Cancellable;
+import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
+
+public class HttpUriRequestBase extends BasicClassicHttpRequest implements CancellableAware, Configurable {
+
+ private static final long serialVersionUID = 1L;
+
+ private RequestConfig requestConfig;
+ private final AtomicBoolean aborted;
+ private final AtomicReference<Cancellable> cancellableRef;
+
+ public HttpUriRequestBase(final String method, final URI requestUri) {
+ super(method, requestUri);
+ this.aborted = new AtomicBoolean(false);
+ this.cancellableRef = new AtomicReference<>(null);
+ }
+
+ public void abort() {
+ if (this.aborted.compareAndSet(false, true)) {
+ final Cancellable cancellable = this.cancellableRef.getAndSet(null);
+ if (cancellable != null) {
+ cancellable.cancel();
+ }
+ }
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return isAborted();
+ }
+
+ public boolean isAborted() {
+ return this.aborted.get();
+ }
+
+ /**
+ * @since 4.2
+ */
+ @Override
+ public void setCancellable(final Cancellable cancellable) {
+ if (!this.aborted.get()) {
+ this.cancellableRef.set(cancellable);
+ }
+ }
+
+ /**
+ * Resets internal state of the request making it reusable.
+ *
+ * @since 4.2
+ */
+ public void reset() {
+ final Cancellable cancellable = this.cancellableRef.getAndSet(null);
+ if (cancellable != null) {
+ cancellable.cancel();
+ }
+ this.aborted.set(false);
+ }
+
+ public void setConfig(final RequestConfig requestConfig) {
+ this.requestConfig = requestConfig;
+ }
+
+ @Override
+ public RequestConfig getConfig() {
+ return requestConfig;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder();
+ sb.append(getMethod()).append(" ").append(getRequestUri());
+ return sb.toString();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/RequestBuilder.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/RequestBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/RequestBuilder.java
new file mode 100644
index 0000000..4e18c89
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/RequestBuilder.java
@@ -0,0 +1,492 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.classic.methods;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.hc.client5.http.StandardMethods;
+import org.apache.hc.client5.http.config.Configurable;
+import org.apache.hc.client5.http.config.RequestConfig;
+import org.apache.hc.client5.http.entity.UrlEncodedFormEntity;
+import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HttpEntity;
+import org.apache.hc.core5.http.HttpVersion;
+import org.apache.hc.core5.http.NameValuePair;
+import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.message.BasicHeader;
+import org.apache.hc.core5.http.message.BasicNameValuePair;
+import org.apache.hc.core5.http.message.HeaderGroup;
+import org.apache.hc.core5.net.URIBuilder;
+import org.apache.hc.core5.util.Args;
+
+/**
+ * Builder for {@link ClassicHttpRequest} instances.
+ * <p>
+ * Please note that this class treats parameters differently depending on composition
+ * of the request: if the request has a content entity explicitly set with
+ * {@link #setEntity(org.apache.hc.core5.http.HttpEntity)} or it is not an entity enclosing method
+ * (such as POST or PUT), parameters will be added to the query component of the request URI.
+ * Otherwise, parameters will be added as a URL encoded {@link UrlEncodedFormEntity entity}.
+ * </p>
+ *
+ * @since 4.3
+ */
+public class RequestBuilder {
+
+ private String method;
+ private Charset charset;
+ private ProtocolVersion version;
+ private URI uri;
+ private HeaderGroup headergroup;
+ private HttpEntity entity;
+ private List<NameValuePair> parameters;
+ private RequestConfig config;
+
+ RequestBuilder(final String method) {
+ super();
+ this.charset = StandardCharsets.UTF_8;
+ this.method = method;
+ }
+
+ RequestBuilder() {
+ }
+
+ RequestBuilder(final StandardMethods method) {
+ this(method.name());
+ }
+
+ RequestBuilder(final String method, final URI uri) {
+ super();
+ this.method = method;
+ this.uri = uri;
+ }
+
+ RequestBuilder(final StandardMethods method, final URI uri) {
+ this(method.name(), uri);
+ }
+
+ RequestBuilder(final String method, final String uri) {
+ super();
+ this.method = method;
+ this.uri = uri != null ? URI.create(uri) : null;
+ }
+
+ RequestBuilder(final StandardMethods method, final String uri) {
+ this(method.name(), uri);
+ }
+
+ public static RequestBuilder create(final String method) {
+ Args.notBlank(method, "HTTP method");
+ return new RequestBuilder(method);
+ }
+
+ public static RequestBuilder get() {
+ return new RequestBuilder(StandardMethods.GET.name());
+ }
+
+ /**
+ * @since 4.4
+ */
+ public static RequestBuilder get(final URI uri) {
+ return new RequestBuilder(StandardMethods.GET, uri);
+ }
+
+ /**
+ * @since 4.4
+ */
+ public static RequestBuilder get(final String uri) {
+ return new RequestBuilder(StandardMethods.GET, uri);
+ }
+
+ public static RequestBuilder head() {
+ return new RequestBuilder(StandardMethods.HEAD);
+ }
+
+ /**
+ * @since 4.4
+ */
+ public static RequestBuilder head(final URI uri) {
+ return new RequestBuilder(StandardMethods.HEAD, uri);
+ }
+
+ /**
+ * @since 4.4
+ */
+ public static RequestBuilder head(final String uri) {
+ return new RequestBuilder(StandardMethods.HEAD, uri);
+ }
+
+ /**
+ * @since 4.4
+ */
+ public static RequestBuilder patch() {
+ return new RequestBuilder(StandardMethods.PATCH.name());
+ }
+
+ /**
+ * @since 4.4
+ */
+ public static RequestBuilder patch(final URI uri) {
+ return new RequestBuilder(StandardMethods.PATCH, uri);
+ }
+
+ /**
+ * @since 4.4
+ */
+ public static RequestBuilder patch(final String uri) {
+ return new RequestBuilder(StandardMethods.PATCH, uri);
+ }
+
+ public static RequestBuilder post() {
+ return new RequestBuilder(StandardMethods.POST);
+ }
+
+ /**
+ * @since 4.4
+ */
+ public static RequestBuilder post(final URI uri) {
+ return new RequestBuilder(StandardMethods.POST, uri);
+ }
+
+ /**
+ * @since 4.4
+ */
+ public static RequestBuilder post(final String uri) {
+ return new RequestBuilder(StandardMethods.POST, uri);
+ }
+
+ public static RequestBuilder put() {
+ return new RequestBuilder(StandardMethods.PUT);
+ }
+
+ /**
+ * @since 4.4
+ */
+ public static RequestBuilder put(final URI uri) {
+ return new RequestBuilder(StandardMethods.PUT, uri);
+ }
+
+ /**
+ * @since 4.4
+ */
+ public static RequestBuilder put(final String uri) {
+ return new RequestBuilder(StandardMethods.PUT, uri);
+ }
+
+ public static RequestBuilder delete() {
+ return new RequestBuilder(StandardMethods.DELETE);
+ }
+
+ /**
+ * @since 4.4
+ */
+ public static RequestBuilder delete(final URI uri) {
+ return new RequestBuilder(StandardMethods.DELETE, uri);
+ }
+
+ /**
+ * @since 4.4
+ */
+ public static RequestBuilder delete(final String uri) {
+ return new RequestBuilder(StandardMethods.DELETE, uri);
+ }
+
+ public static RequestBuilder trace() {
+ return new RequestBuilder(StandardMethods.TRACE);
+ }
+
+ /**
+ * @since 4.4
+ */
+ public static RequestBuilder trace(final URI uri) {
+ return new RequestBuilder(StandardMethods.TRACE, uri);
+ }
+
+ /**
+ * @since 4.4
+ */
+ public static RequestBuilder trace(final String uri) {
+ return new RequestBuilder(StandardMethods.TRACE, uri);
+ }
+
+ public static RequestBuilder options() {
+ return new RequestBuilder(StandardMethods.OPTIONS);
+ }
+
+ /**
+ * @since 4.4
+ */
+ public static RequestBuilder options(final URI uri) {
+ return new RequestBuilder(StandardMethods.OPTIONS, uri);
+ }
+
+ /**
+ * @since 4.4
+ */
+ public static RequestBuilder options(final String uri) {
+ return new RequestBuilder(StandardMethods.OPTIONS, uri);
+ }
+
+ public static RequestBuilder copy(final ClassicHttpRequest request) {
+ Args.notNull(request, "HTTP request");
+ return new RequestBuilder().doCopy(request);
+ }
+
+ private RequestBuilder doCopy(final ClassicHttpRequest request) {
+ if (request == null) {
+ return this;
+ }
+ method = request.getMethod();
+ version = request.getVersion();
+
+ if (headergroup == null) {
+ headergroup = new HeaderGroup();
+ }
+ headergroup.clear();
+ headergroup.setHeaders(request.getAllHeaders());
+
+ parameters = null;
+ entity = null;
+
+ final HttpEntity originalEntity = request.getEntity();
+ final ContentType contentType = EntityUtils.getContentType(originalEntity);
+ if (contentType != null &&
+ contentType.getMimeType().equals(ContentType.APPLICATION_FORM_URLENCODED.getMimeType())) {
+ try {
+ final List<NameValuePair> formParams = EntityUtils.parse(originalEntity);
+ if (!formParams.isEmpty()) {
+ parameters = formParams;
+ }
+ } catch (final IOException ignore) {
+ }
+ } else {
+ entity = originalEntity;
+ }
+
+ try {
+ uri = request.getUri();
+ } catch (final URISyntaxException ignore) {
+ }
+ if (request instanceof Configurable) {
+ config = ((Configurable) request).getConfig();
+ } else {
+ config = null;
+ }
+ return this;
+ }
+
+ /**
+ * @since 4.4
+ */
+ public RequestBuilder setCharset(final Charset charset) {
+ this.charset = charset;
+ return this;
+ }
+
+ /**
+ * @since 4.4
+ */
+ public Charset getCharset() {
+ return charset;
+ }
+
+ public String getMethod() {
+ return method;
+ }
+
+ public ProtocolVersion getVersion() {
+ return version;
+ }
+
+ public RequestBuilder setVersion(final ProtocolVersion version) {
+ this.version = version;
+ return this;
+ }
+
+ public URI getUri() {
+ return uri;
+ }
+
+ public RequestBuilder setUri(final URI uri) {
+ this.uri = uri;
+ return this;
+ }
+
+ public RequestBuilder setUri(final String uri) {
+ this.uri = uri != null ? URI.create(uri) : null;
+ return this;
+ }
+
+ public Header getFirstHeader(final String name) {
+ return headergroup != null ? headergroup.getFirstHeader(name) : null;
+ }
+
+ public Header getLastHeader(final String name) {
+ return headergroup != null ? headergroup.getLastHeader(name) : null;
+ }
+
+ public Header[] getHeaders(final String name) {
+ return headergroup != null ? headergroup.getHeaders(name) : null;
+ }
+
+ public RequestBuilder addHeader(final Header header) {
+ if (headergroup == null) {
+ headergroup = new HeaderGroup();
+ }
+ headergroup.addHeader(header);
+ return this;
+ }
+
+ public RequestBuilder addHeader(final String name, final String value) {
+ if (headergroup == null) {
+ headergroup = new HeaderGroup();
+ }
+ this.headergroup.addHeader(new BasicHeader(name, value));
+ return this;
+ }
+
+ public RequestBuilder removeHeader(final Header header) {
+ if (headergroup == null) {
+ headergroup = new HeaderGroup();
+ }
+ headergroup.removeHeader(header);
+ return this;
+ }
+
+ public RequestBuilder removeHeaders(final String name) {
+ if (name == null || headergroup == null) {
+ return this;
+ }
+ for (final Iterator<Header> i = headergroup.headerIterator(); i.hasNext(); ) {
+ final Header header = i.next();
+ if (name.equalsIgnoreCase(header.getName())) {
+ i.remove();
+ }
+ }
+ return this;
+ }
+
+ public RequestBuilder setHeader(final Header header) {
+ if (headergroup == null) {
+ headergroup = new HeaderGroup();
+ }
+ this.headergroup.setHeader(header);
+ return this;
+ }
+
+ public RequestBuilder setHeader(final String name, final String value) {
+ if (headergroup == null) {
+ headergroup = new HeaderGroup();
+ }
+ this.headergroup.setHeader(new BasicHeader(name, value));
+ return this;
+ }
+
+ public HttpEntity getEntity() {
+ return entity;
+ }
+
+ public RequestBuilder setEntity(final HttpEntity entity) {
+ this.entity = entity;
+ return this;
+ }
+
+ public List<NameValuePair> getParameters() {
+ return parameters != null ? new ArrayList<>(parameters) :
+ new ArrayList<NameValuePair>();
+ }
+
+ public RequestBuilder addParameter(final NameValuePair nvp) {
+ Args.notNull(nvp, "Name value pair");
+ if (parameters == null) {
+ parameters = new LinkedList<>();
+ }
+ parameters.add(nvp);
+ return this;
+ }
+
+ public RequestBuilder addParameter(final String name, final String value) {
+ return addParameter(new BasicNameValuePair(name, value));
+ }
+
+ public RequestBuilder addParameters(final NameValuePair... nvps) {
+ for (final NameValuePair nvp: nvps) {
+ addParameter(nvp);
+ }
+ return this;
+ }
+
+ public RequestConfig getConfig() {
+ return config;
+ }
+
+ public RequestBuilder setConfig(final RequestConfig config) {
+ this.config = config;
+ return this;
+ }
+
+ public ClassicHttpRequest build() {
+ URI uriNotNull = this.uri != null ? this.uri : URI.create("/");
+ HttpEntity entityCopy = this.entity;
+ if (parameters != null && !parameters.isEmpty()) {
+ if (entityCopy == null && (StandardMethods.POST.name().equalsIgnoreCase(method)
+ || StandardMethods.PUT.name().equalsIgnoreCase(method))) {
+ entityCopy = new UrlEncodedFormEntity(parameters, charset != null ? charset : StandardCharsets.ISO_8859_1);
+ } else {
+ try {
+ uriNotNull = new URIBuilder(uriNotNull)
+ .setCharset(this.charset)
+ .addParameters(parameters)
+ .build();
+ } catch (final URISyntaxException ex) {
+ // should never happen
+ }
+ }
+ }
+ final HttpUriRequestBase result = new HttpUriRequestBase(method, uriNotNull);
+ result.setVersion(this.version != null ? this.version : HttpVersion.HTTP_1_1);
+ if (this.headergroup != null) {
+ result.setHeaders(this.headergroup.getAllHeaders());
+ }
+ result.setEntity(entityCopy);
+ result.setConfig(this.config);
+ return result;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/package-info.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/package-info.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/package-info.java
new file mode 100644
index 0000000..e0c25d2
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/package-info.java
@@ -0,0 +1,31 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+/**
+ * Standard HTTP method implementations.
+ */
+package org.apache.hc.client5.http.classic.methods;
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/main/java/org/apache/hc/client5/http/classic/package-info.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/package-info.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/package-info.java
new file mode 100644
index 0000000..53fc069
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/package-info.java
@@ -0,0 +1,31 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+/**
+ * Client HTTP communication APIs.
+ */
+package org.apache.hc.client5.http.classic;
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ChainElements.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ChainElements.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ChainElements.java
new file mode 100644
index 0000000..d570a4b
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ChainElements.java
@@ -0,0 +1,34 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.impl;
+
+public enum ChainElements {
+
+ REDIRECT, BACK_OFF, RETRY_SERVICE_UNAVAILABLE, RETRY_IO_ERROR, PROTOCOL, CONNECT, MAIN_TRANSPORT
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/main/java/org/apache/hc/client5/http/impl/CookieSpecRegistries.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/CookieSpecRegistries.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/CookieSpecRegistries.java
new file mode 100644
index 0000000..c114e05
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/CookieSpecRegistries.java
@@ -0,0 +1,82 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.impl;
+
+import org.apache.hc.client5.http.config.CookieSpecs;
+import org.apache.hc.client5.http.cookie.CookieSpecProvider;
+import org.apache.hc.client5.http.impl.cookie.IgnoreSpecProvider;
+import org.apache.hc.client5.http.impl.cookie.RFC6265CookieSpecProvider;
+import org.apache.hc.client5.http.psl.PublicSuffixMatcher;
+import org.apache.hc.client5.http.psl.PublicSuffixMatcherLoader;
+import org.apache.hc.core5.http.config.Lookup;
+import org.apache.hc.core5.http.config.RegistryBuilder;
+
+/**
+ * @since 4.5
+ */
+public final class CookieSpecRegistries {
+
+ /**
+ * Creates a builder containing the default registry entries, using the provided public suffix matcher.
+ */
+ public static RegistryBuilder<CookieSpecProvider> createDefaultBuilder(final PublicSuffixMatcher publicSuffixMatcher) {
+ final CookieSpecProvider laxStandardProvider = new RFC6265CookieSpecProvider(
+ RFC6265CookieSpecProvider.CompatibilityLevel.RELAXED, publicSuffixMatcher);
+ final CookieSpecProvider strictStandardProvider = new RFC6265CookieSpecProvider(
+ RFC6265CookieSpecProvider.CompatibilityLevel.STRICT, publicSuffixMatcher);
+ return RegistryBuilder.<CookieSpecProvider>create()
+ .register(CookieSpecs.DEFAULT, laxStandardProvider)
+ .register(CookieSpecs.STANDARD, laxStandardProvider)
+ .register(CookieSpecs.STANDARD_STRICT, strictStandardProvider)
+ .register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecProvider());
+ }
+
+ /**
+ * Creates a builder containing the default registry entries with the default public suffix matcher.
+ */
+ public static RegistryBuilder<CookieSpecProvider> createDefaultBuilder() {
+ return createDefaultBuilder(PublicSuffixMatcherLoader.getDefault());
+ }
+
+ /**
+ * Creates the default registry, using the default public suffix matcher.
+ */
+ public static Lookup<CookieSpecProvider> createDefault() {
+ return createDefault(PublicSuffixMatcherLoader.getDefault());
+ }
+
+ /**
+ * Creates the default registry with the provided public suffix matcher
+ */
+ public static Lookup<CookieSpecProvider> createDefault(final PublicSuffixMatcher publicSuffixMatcher) {
+ return createDefaultBuilder(publicSuffixMatcher).build();
+ }
+
+ private CookieSpecRegistries() {}
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultAuthenticationStrategy.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultAuthenticationStrategy.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultAuthenticationStrategy.java
new file mode 100644
index 0000000..8923361
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultAuthenticationStrategy.java
@@ -0,0 +1,123 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.impl;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import org.apache.hc.client5.http.AuthenticationStrategy;
+import org.apache.hc.client5.http.auth.AuthChallenge;
+import org.apache.hc.client5.http.auth.AuthScheme;
+import org.apache.hc.client5.http.auth.AuthSchemeProvider;
+import org.apache.hc.client5.http.auth.ChallengeType;
+import org.apache.hc.client5.http.config.AuthSchemes;
+import org.apache.hc.client5.http.config.RequestConfig;
+import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.config.Lookup;
+import org.apache.hc.core5.http.protocol.HttpContext;
+import org.apache.hc.core5.util.Args;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+/**
+ * Default implementation of {@link AuthenticationStrategy}
+ *
+ * @since 5.0
+ */
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
+public class DefaultAuthenticationStrategy implements AuthenticationStrategy {
+
+ private final Logger log = LogManager.getLogger(getClass());
+
+ public static final DefaultAuthenticationStrategy INSTANCE = new DefaultAuthenticationStrategy();
+
+ private static final List<String> DEFAULT_SCHEME_PRIORITY =
+ Collections.unmodifiableList(Arrays.asList(
+ AuthSchemes.SPNEGO,
+ AuthSchemes.KERBEROS,
+ AuthSchemes.NTLM,
+ AuthSchemes.CREDSSP,
+ AuthSchemes.DIGEST,
+ AuthSchemes.BASIC));
+
+ @Override
+ public List<AuthScheme> select(
+ final ChallengeType challengeType,
+ final Map<String, AuthChallenge> challenges,
+ final HttpContext context) {
+ Args.notNull(challengeType, "ChallengeType");
+ Args.notNull(challenges, "Map of auth challenges");
+ Args.notNull(context, "HTTP context");
+ final HttpClientContext clientContext = HttpClientContext.adapt(context);
+
+ final List<AuthScheme> options = new ArrayList<>();
+ final Lookup<AuthSchemeProvider> registry = clientContext.getAuthSchemeRegistry();
+ if (registry == null) {
+ this.log.debug("Auth scheme registry not set in the context");
+ return options;
+ }
+ final RequestConfig config = clientContext.getRequestConfig();
+ Collection<String> authPrefs = challengeType == ChallengeType.TARGET ?
+ config.getTargetPreferredAuthSchemes() : config.getProxyPreferredAuthSchemes();
+ if (authPrefs == null) {
+ authPrefs = DEFAULT_SCHEME_PRIORITY;
+ }
+ if (this.log.isDebugEnabled()) {
+ this.log.debug("Authentication schemes in the order of preference: " + authPrefs);
+ }
+
+ for (final String id: authPrefs) {
+ final AuthChallenge challenge = challenges.get(id.toLowerCase(Locale.ROOT));
+ if (challenge != null) {
+ final AuthSchemeProvider authSchemeProvider = registry.lookup(id);
+ if (authSchemeProvider == null) {
+ if (this.log.isWarnEnabled()) {
+ this.log.warn("Authentication scheme " + id + " not supported");
+ // Try again
+ }
+ continue;
+ }
+ final AuthScheme authScheme = authSchemeProvider.create(context);
+ options.add(authScheme);
+ } else {
+ if (this.log.isDebugEnabled()) {
+ this.log.debug("Challenge for " + id + " authentication scheme not available");
+ }
+ }
+ }
+ return options;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryHandler.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryHandler.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryHandler.java
new file mode 100644
index 0000000..ca9cce0
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryHandler.java
@@ -0,0 +1,183 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.impl;
+
+import java.io.IOException;
+import java.io.InterruptedIOException;
+import java.net.ConnectException;
+import java.net.UnknownHostException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.net.ssl.SSLException;
+
+import org.apache.hc.client5.http.HttpRequestRetryHandler;
+import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.protocol.HttpContext;
+import org.apache.hc.core5.util.Args;
+
+/**
+ * The default {@link HttpRequestRetryHandler} used by request executors.
+ *
+ * @since 4.0
+ */
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
+public class DefaultHttpRequestRetryHandler implements HttpRequestRetryHandler {
+
+ public static final DefaultHttpRequestRetryHandler INSTANCE = new DefaultHttpRequestRetryHandler();
+
+ /** the number of times a method will be retried */
+ private final int retryCount;
+
+ private final Map<String, Boolean> idempotentMethods;
+ private final Set<Class<? extends IOException>> nonRetriableClasses;
+
+ /**
+ * Create the request retry handler using the specified IOException classes
+ *
+ * @param retryCount how many times to retry; 0 means no retries
+ * @param requestSentRetryEnabled true if it's OK to retry requests that have been sent
+ * @param clazzes the IOException types that should not be retried
+ * @since 4.3
+ */
+ protected DefaultHttpRequestRetryHandler(
+ final int retryCount,
+ final boolean requestSentRetryEnabled,
+ final Collection<Class<? extends IOException>> clazzes) {
+ super();
+ this.retryCount = retryCount;
+ this.idempotentMethods = new ConcurrentHashMap<>();
+ this.idempotentMethods.put("GET", Boolean.TRUE);
+ this.idempotentMethods.put("HEAD", Boolean.TRUE);
+ this.idempotentMethods.put("PUT", Boolean.TRUE);
+ this.idempotentMethods.put("DELETE", Boolean.TRUE);
+ this.idempotentMethods.put("OPTIONS", Boolean.TRUE);
+ this.idempotentMethods.put("TRACE", Boolean.TRUE);
+ this.nonRetriableClasses = new HashSet<>();
+ for (final Class<? extends IOException> clazz: clazzes) {
+ this.nonRetriableClasses.add(clazz);
+ }
+ }
+
+ /**
+ * Create the request retry handler using the following list of
+ * non-retriable IOException classes: <br>
+ * <ul>
+ * <li>InterruptedIOException</li>
+ * <li>UnknownHostException</li>
+ * <li>ConnectException</li>
+ * <li>SSLException</li>
+ * </ul>
+ * @param retryCount how many times to retry; 0 means no retries
+ * @param requestSentRetryEnabled true if it's OK to retry non-idempotent requests that have been sent
+ */
+ @SuppressWarnings("unchecked")
+ public DefaultHttpRequestRetryHandler(final int retryCount, final boolean requestSentRetryEnabled) {
+ this(retryCount, requestSentRetryEnabled, Arrays.asList(
+ InterruptedIOException.class,
+ UnknownHostException.class,
+ ConnectException.class,
+ SSLException.class));
+ }
+
+ /**
+ * Create the request retry handler with a retry count of 3, requestSentRetryEnabled false
+ * and using the following list of non-retriable IOException classes: <br>
+ * <ul>
+ * <li>InterruptedIOException</li>
+ * <li>UnknownHostException</li>
+ * <li>ConnectException</li>
+ * <li>SSLException</li>
+ * </ul>
+ */
+ public DefaultHttpRequestRetryHandler() {
+ this(3, false);
+ }
+
+ /**
+ * Used {@code retryCount} and {@code requestSentRetryEnabled} to determine
+ * if the given method should be retried.
+ */
+ @Override
+ public boolean retryRequest(
+ final HttpRequest request,
+ final IOException exception,
+ final int executionCount,
+ final HttpContext context) {
+ Args.notNull(request, "HTTP request");
+ Args.notNull(exception, "I/O exception");
+
+ if (executionCount > this.retryCount) {
+ // Do not retry if over max retry count
+ return false;
+ }
+ if (this.nonRetriableClasses.contains(exception.getClass())) {
+ return false;
+ } else {
+ for (final Class<? extends IOException> rejectException : this.nonRetriableClasses) {
+ if (rejectException.isInstance(exception)) {
+ return false;
+ }
+ }
+ }
+ if (request instanceof HttpUriRequestBase && ((HttpUriRequestBase)request).isAborted()) {
+ return false;
+ }
+ if (handleAsIdempotent(request)) {
+ // Retry if the request is considered idempotent
+ return true;
+ }
+ // otherwise do not retry
+ return false;
+ }
+
+ /**
+ * @return the maximum number of times a method will be retried
+ */
+ public int getRetryCount() {
+ return retryCount;
+ }
+
+ /**
+ * @since 4.2
+ */
+ protected boolean handleAsIdempotent(final HttpRequest request) {
+ final String method = request.getMethod().toUpperCase(Locale.ROOT);
+ final Boolean b = this.idempotentMethods.get(method);
+ return b != null && b.booleanValue();
+ }
+
+}