Apache Solr open-source search software
SOLR-4110: Configurable Content-Type headers for PHPResponseWriters and PHPSerializedResponseWriter.
Mark Robert Miller89a55d2e873b
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex cf58c232508..dbb00cdd2a6 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -34,7 +34,7 @@ Velocity 1.6.4 and Velocity Tools 2.0Apache UIMA 2.3.1Apache ZooKeeper 3.4.5-Upgrading from Solr 4.0.0-BETA+Upgrading from Solr 4.0.0----------------------Custom java parsing plugins need to migrade from throwing the internal@@ -154,6 +154,9 @@ New Features* SOLR-4120: Collection API: Support for specifying a list of Solr addresses tospread a new collection across. (Per Steffensen via Mark Miller)+* SOLR-4110: Configurable Content-Type headers for PHPResponseWriters and+ PHPSerializedResponseWriter. (Dominik Siebel via Mark Miller)+Optimizations----------------------diff --git a/solr/core/src/java/org/apache/solr/response/PHPResponseWriter.java b/solr/core/src/java/org/apache/solr/response/PHPResponseWriter.javaindex 62a1749bb53..24de3462c12 100755--- a/solr/core/src/java/org/apache/solr/response/PHPResponseWriter.java+++ b/solr/core/src/java/org/apache/solr/response/PHPResponseWriter.java@@ -26,13 +26,18 @@ import org.apache.solr.request.SolrQueryRequest;public class PHPResponseWriter implements QueryResponseWriter {static String CONTENT_TYPE_PHP_UTF8="text/x-php;charset=UTF-8";+ private String contentType = CONTENT_TYPE_PHP_UTF8;+@Override- public void init(NamedList n) {- /* NOOP */+ public void init(NamedList namedList) {+ String contentType = (String) namedList.get("content-type");+ if (contentType != null) {+ this.contentType = contentType;+ }}-- @Override-public void write(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) throws IOException {++ @Override+ public void write(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) throws IOException {PHPWriter w = new PHPWriter(writer, req, rsp);try {w.writeResponse();@@ -43,7 +48,7 @@ public void write(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) th@Overridepublic String getContentType(SolrQueryRequest request, SolrQueryResponse response) {- return CONTENT_TYPE_TEXT_UTF8;+ return contentType;}}diff --git a/solr/core/src/java/org/apache/solr/response/PHPSerializedResponseWriter.java b/solr/core/src/java/org/apache/solr/response/PHPSerializedResponseWriter.javaindex 17f58d08fcd..5e0f3f40a4b 100755--- a/solr/core/src/java/org/apache/solr/response/PHPSerializedResponseWriter.java+++ b/solr/core/src/java/org/apache/solr/response/PHPSerializedResponseWriter.java@@ -41,12 +41,18 @@ import org.apache.solr.search.ReturnFields;public class PHPSerializedResponseWriter implements QueryResponseWriter {static String CONTENT_TYPE_PHP_UTF8="text/x-php-serialized;charset=UTF-8";+ private String contentType = CONTENT_TYPE_PHP_UTF8;+@Override- public void init(NamedList n) {+ public void init(NamedList namedList) {+ String contentType = (String) namedList.get("content-type");+ if (contentType != null) {+ this.contentType = contentType;+ }}- @Override-public void write(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) throws IOException {+ @Override+ public void write(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) throws IOException {PHPSerializedWriter w = new PHPSerializedWriter(writer, req, rsp);try {w.writeResponse();@@ -57,7 +63,7 @@ public void write(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) th@Overridepublic String getContentType(SolrQueryRequest request, SolrQueryResponse response) {- return CONTENT_TYPE_TEXT_UTF8;+ return contentType;}}