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

Cherry pick #9990 #10204

Merged
merged 1 commit into from
Jan 10, 2024
Merged
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
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
Loading