Skip to content

Commit

Permalink
Cherry pick #9990 (#10204)
Browse files Browse the repository at this point in the history
Co-authored-by: Nils-Helge Garli Hegvik <nilsga@gmail.com>
  • Loading branch information
laurit and nilsga committed Jan 10, 2024
1 parent df10cf0 commit 00b52a9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ public class RequestWithHost extends HttpRequestWrapper implements ClassicHttpRe

public RequestWithHost(HttpHost httpHost, ClassicHttpRequest httpRequest) {
super(httpRequest);

this.scheme = httpHost.getSchemeName();
this.authority = new URIAuthority(httpHost.getHostName(), httpHost.getPort());
if (httpHost != null) {
this.scheme = httpHost.getSchemeName();
this.authority = new URIAuthority(httpHost.getHostName(), httpHost.getPort());
} else {
this.scheme = httpRequest.getScheme();
this.authority = httpRequest.getAuthority();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.hc.client5.http.impl.classic.HttpClients;
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.message.BasicClassicHttpRequest;
Expand Down Expand Up @@ -90,6 +91,26 @@ void executeRequestWithCallback(ClassicHttpRequest request, URI uri, HttpClientR
}
}

@Nested
class ApacheClientNullHttpHostRequestTest extends AbstractTest {
@Override
ClassicHttpRequest createRequest(String method, URI uri) {
// also testing with an absolute path below
return new BasicClassicHttpRequest(method, HttpHost.create(uri), fullPathFromUri(uri));
}

@Override
ClassicHttpResponse doExecuteRequest(ClassicHttpRequest request, URI uri) throws Exception {
return getClient(uri).execute(null, request);
}

@Override
void executeRequestWithCallback(ClassicHttpRequest request, URI uri, HttpClientResult result)
throws Exception {
getClient(uri).execute(null, request, new ResponseHandler(result));
}
}

@Nested
class ApacheClientHostAbsoluteUriRequestTest extends AbstractTest {
@Override
Expand Down

0 comments on commit 00b52a9

Please sign in to comment.