Apache Lucene open-source search software
SOLR-8501: Specify the entity request size when known in HttpSolrClient.
Mark Robert Miller32fc5285f6a1
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex b06b72a6274..a2eee31c9af 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -393,6 +393,11 @@ Bug Fixes* SOLR-8453: Solr should attempt to consume the request inputstream on errors as we cannotcount on the container to do it. (Mark Miller, Greg Wilkins, yonik, Joakim Erdfelt)+Optimizations+----------------------++* SOLR-8501: Specify the entity request size when known in HttpSolrClient. (Mark Miller)+Other Changes----------------------diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.javaindex b529fa965f8..1f526dc286c 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java@@ -435,7 +435,8 @@ public class HttpSolrClient extends SolrClient {break;}if (contentStream[0] instanceof RequestWriter.LazyContentStream) {- postOrPut.setEntity(new InputStreamEntity(contentStream[0].getStream(), -1) {+ Long size = contentStream[0].getSize();+ postOrPut.setEntity(new InputStreamEntity(contentStream[0].getStream(), size == null ? -1 : size) {@Overridepublic Header getContentType() {return new BasicHeader("Content-Type", contentStream[0].getContentType());@@ -448,7 +449,8 @@ public class HttpSolrClient extends SolrClient {});} else {- postOrPut.setEntity(new InputStreamEntity(contentStream[0].getStream(), -1) {+ Long size = contentStream[0].getSize();+ postOrPut.setEntity(new InputStreamEntity(contentStream[0].getStream(), size == null ? -1 : size) {@Overridepublic Header getContentType() {return new BasicHeader("Content-Type", contentStream[0].getContentType());diff --git a/solr/solrj/src/java/org/apache/solr/common/util/ContentStreamBase.java b/solr/solrj/src/java/org/apache/solr/common/util/ContentStreamBase.javaindex eb0bbceb956..b70fed5850d 100644--- a/solr/solrj/src/java/org/apache/solr/common/util/ContentStreamBase.java+++ b/solr/solrj/src/java/org/apache/solr/common/util/ContentStreamBase.java@@ -25,6 +25,7 @@ import java.io.InputStream;import java.io.InputStreamReader;import java.io.Reader;import java.io.StringReader;+import java.io.UnsupportedEncodingException;import java.net.URL;import java.net.URLConnection;import java.nio.charset.StandardCharsets;@@ -150,7 +151,12 @@ public abstract class ContentStreamBase implements ContentStreamthis.str = str;this.contentType = contentType;name = null;- size = new Long( str.length() );+ try {+ size = new Long( str.getBytes(DEFAULT_CHARSET).length );+ } catch (UnsupportedEncodingException e) {+ // won't happen+ throw new RuntimeException(e);+ }sourceInfo = "string";}