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

Check HttpHost instance for null prior to dereferencing it #1722

Merged
merged 1 commit into from
Feb 5, 2024
Merged
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 @@ -7,6 +7,7 @@

package org.apache.hc.client5.http.classic;

import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
Expand All @@ -24,6 +25,7 @@
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.logging.Level;

@Weave(type = MatchType.Interface, originalName = "org.apache.hc.client5.http.classic.HttpClient")
public class HttpClient_Instrumentation {
Expand Down Expand Up @@ -181,9 +183,17 @@ public <T> T execute(HttpHost target, ClassicHttpRequest request, HttpContext co
}

private static URI getUri(HttpHost target, HttpRequest request) throws URISyntaxException {
URI requestURI = new URI(request.getRequestUri());
String scheme = requestURI.getScheme() == null ? target.getSchemeName() : requestURI.getScheme();
return new URI(scheme, null, target.getHostName(), target.getPort(), requestURI.getPath(), null, null);
}
String path = request.getPath();

// Prefer pulling the remainder of the host info from the HttpPost instance
if (target != null) {
return new URI(target.getSchemeName(), null, target.getHostName(), target.getPort(), path, null, null);
} else { // Pull from the HttpRequest object
URI requestURI = new URI(request.getUri().toString());
String scheme = request.getScheme();
int port = requestURI.getPort() != -1 ? requestURI.getPort() :
("http".equals(scheme) ? 80 : 443);
return new URI(scheme, null, requestURI.getHost(), port, path, null, null);
}
}
}
Loading