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

SOLR-17611 SolrJ User-Agent, pass Solr version #2927

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 @@ -339,7 +339,7 @@ public void writeTo(OutputStream out) throws IOException {
method.setConfig(requestConfigBuilder.build());

method.setEntity(template);
method.addHeader("User-Agent", HttpSolrClient.AGENT);
method.addHeader("User-Agent", HttpSolrClient.USER_AGENT);
method.addHeader("Content-Type", contentType);

response =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,15 @@
* </ul>
*/
public class Http2SolrClient extends HttpSolrClientBase {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public static final String REQ_PRINCIPAL_KEY = "solr-req-principal";
private static final String USER_AGENT =
"Solr["
+ MethodHandles.lookup().lookupClass().getName()
+ "] "
+ MethodHandles.lookup().lookupClass().getPackage().getSpecificationVersion();

private static volatile SSLConfig defaultSSLConfig;
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private static final String AGENT = "Solr[" + Http2SolrClient.class.getName() + "] 2.0";

private final HttpClient httpClient;

Expand Down Expand Up @@ -251,7 +255,7 @@ private HttpClient createHttpClient(Builder builder) {
httpClient.setFollowRedirects(false);
httpClient.setMaxRequestsQueuedPerDestination(
asyncTracker.getMaxRequestsQueuedPerDestination());
httpClient.setUserAgentField(new HttpField(HttpHeader.USER_AGENT, AGENT));
httpClient.setUserAgentField(new HttpField(HttpHeader.USER_AGENT, USER_AGENT));
httpClient.setIdleTimeout(idleTimeoutMillis);

if (builder.cookieStore != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ public class HttpJdkSolrClient extends HttpSolrClientBase {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

private static final String USER_AGENT =
"Solr[" + MethodHandles.lookup().lookupClass().getName() + "] 1.0";
"Solr["
+ MethodHandles.lookup().lookupClass().getName()
+ "] "
+ MethodHandles.lookup().lookupClass().getPackage().getSpecificationVersion();

protected HttpClient httpClient;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SolrNamedThreadFactory;
import org.apache.solr.common.util.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

/**
Expand All @@ -98,15 +96,15 @@
public class HttpSolrClient extends BaseHttpSolrClient {

private static final Charset FALLBACK_CHARSET = StandardCharsets.UTF_8;
private static final String DEFAULT_PATH = "/select";
private static final long serialVersionUID = -946812319974801896L;

protected static final Set<Integer> UNMATCHED_ACCEPTED_ERROR_CODES = Collections.singleton(429);

/** User-Agent String. */
public static final String AGENT = "Solr[" + HttpSolrClient.class.getName() + "] 1.0";

private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
static final String USER_AGENT =
"Solr["
+ MethodHandles.lookup().lookupClass().getName()
+ "] "
+ MethodHandles.lookup().lookupClass().getPackage().getSpecificationVersion();

static final Class<HttpSolrClient> cacheKey = HttpSolrClient.class;

Expand Down Expand Up @@ -542,7 +540,7 @@ protected NamedList<Object> executeMethod(
final ResponseParser processor,
final boolean isV2Api)
throws SolrServerException {
method.addHeader("User-Agent", AGENT);
method.addHeader("User-Agent", USER_AGENT);

org.apache.http.client.config.RequestConfig.Builder requestConfigBuilder =
HttpClientUtil.createDefaultRequestConfigBuilder();
Expand Down
Loading