Skip to content
Permalink
Browse files
Reuse org.apache.hc.core5.http.Method HTTP spec enum
  • Loading branch information
arturobernalg authored and ok2c committed Mar 16, 2021
1 parent 10e2deb commit 879a063b570bb9dd15022db01c855dc71304b0f8
Showing 7 changed files with 15 additions and 8 deletions.
@@ -46,6 +46,7 @@
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.HttpVersion;
import org.apache.hc.core5.http.Method;
import org.apache.hc.core5.http.ProtocolVersion;
import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
@@ -353,11 +354,11 @@ public static final void assert110WarningFound(final HttpResponse response) {
}

public static ClassicHttpRequest makeDefaultRequest() {
return new BasicClassicHttpRequest("GET", "/");
return new BasicClassicHttpRequest(Method.GET.toString(), "/");
}

public static ClassicHttpRequest makeDefaultHEADRequest() {
return new BasicClassicHttpRequest("HEAD", "/");
return new BasicClassicHttpRequest(Method.HEAD.toString(), "/");
}

public static ClassicHttpResponse make500Response() {
@@ -57,6 +57,7 @@
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.HttpVersion;
import org.apache.hc.core5.http.Method;
import org.apache.hc.core5.http.message.BasicHttpRequest;
import org.apache.hc.core5.http.message.StatusLine;
import org.apache.hc.core5.http.nio.AsyncDataConsumer;
@@ -332,7 +333,7 @@ private void createTunnel(

final AuthExchange proxyAuthExchange = proxy != null ? clientContext.getAuthExchange(proxy) : new AuthExchange();

final HttpRequest connect = new BasicHttpRequest("CONNECT", nextHop, nextHop.toHostString());
final HttpRequest connect = new BasicHttpRequest(Method.CONNECT, nextHop, nextHop.toHostString());
connect.setVersion(HttpVersion.HTTP_1_1);

proxyHttpProcessor.process(connect, null, clientContext);
@@ -56,6 +56,7 @@
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.HttpVersion;
import org.apache.hc.core5.http.Method;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
import org.apache.hc.core5.http.message.StatusLine;
@@ -209,7 +210,7 @@ private boolean createTunnelToTarget(
ClassicHttpResponse response = null;

final String authority = target.toHostString();
final ClassicHttpRequest connect = new BasicClassicHttpRequest("CONNECT", target, authority);
final ClassicHttpRequest connect = new BasicClassicHttpRequest(Method.CONNECT, target, authority);
connect.setVersion(HttpVersion.HTTP_1_1);

this.proxyHttpProcessor.process(connect, null, context);
@@ -61,6 +61,7 @@
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHeaders;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.Method;
import org.apache.hc.core5.http.config.CharCodingConfig;
import org.apache.hc.core5.http.config.Http1Config;
import org.apache.hc.core5.http.config.Lookup;
@@ -158,7 +159,7 @@ public Socket tunnel(
final HttpContext context = new BasicHttpContext();
ClassicHttpResponse response;

final ClassicHttpRequest connect = new BasicClassicHttpRequest("CONNECT", host.toHostString());
final ClassicHttpRequest connect = new BasicClassicHttpRequest(Method.CONNECT, host.toHostString());

final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(proxy), credentials);
@@ -47,6 +47,7 @@
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpRequestInterceptor;
import org.apache.hc.core5.http.Method;
import org.apache.hc.core5.http.config.Lookup;
import org.apache.hc.core5.http.protocol.HttpContext;
import org.apache.hc.core5.net.URIAuthority;
@@ -78,7 +79,7 @@ public void process(final HttpRequest request, final EntityDetails entity, final
Args.notNull(context, "HTTP context");

final String method = request.getMethod();
if (method.equalsIgnoreCase("CONNECT") || method.equalsIgnoreCase("TRACE")) {
if (Method.CONNECT.isSame(method) || Method.TRACE.isSame(method)) {
return;
}

@@ -38,6 +38,7 @@
import org.apache.hc.core5.http.HttpHeaders;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpRequestInterceptor;
import org.apache.hc.core5.http.Method;
import org.apache.hc.core5.http.protocol.HttpContext;
import org.apache.hc.core5.util.Args;
import org.slf4j.Logger;
@@ -65,7 +66,7 @@ public void process(final HttpRequest request, final EntityDetails entity, final
Args.notNull(request, "HTTP request");

final String method = request.getMethod();
if (method.equalsIgnoreCase("CONNECT")) {
if (Method.CONNECT.isSame(method)) {
return;
}

@@ -37,6 +37,7 @@
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpRequestInterceptor;
import org.apache.hc.core5.http.Method;
import org.apache.hc.core5.http.protocol.HttpContext;
import org.apache.hc.core5.util.Args;

@@ -68,7 +69,7 @@ public void process(final HttpRequest request, final EntityDetails entity, final
Args.notNull(request, "HTTP request");

final String method = request.getMethod();
if (method.equalsIgnoreCase("CONNECT")) {
if (Method.CONNECT.isSame(method)) {
return;
}

0 comments on commit 879a063

Please sign in to comment.