You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rj...@apache.org on 2013/12/03 17:38:26 UTC
svn commit: r1547467 - in /lucene/dev/branches/branch_4x: ./ solr/
solr/core/ solr/core/src/java/org/apache/solr/handler/
solr/core/src/java/org/apache/solr/handler/component/
solr/core/src/java/org/apache/solr/servlet/
solr/core/src/test/org/apache/so...
Author: rjernst
Date: Tue Dec 3 16:38:25 2013
New Revision: 1547467
URL: http://svn.apache.org/r1547467
Log:
SOLR-5517: Return HTTP error on POST requests with no Content-Type
Modified:
lucene/dev/branches/branch_4x/ (props changed)
lucene/dev/branches/branch_4x/solr/ (props changed)
lucene/dev/branches/branch_4x/solr/CHANGES.txt (contents, props changed)
lucene/dev/branches/branch_4x/solr/core/ (props changed)
lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/UpdateRequestHandler.java
lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java
lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java
lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/request/TestRemoteStreaming.java
lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/servlet/SolrRequestParserTest.java
lucene/dev/branches/branch_4x/solr/solrj/ (props changed)
lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/SolrException.java
Modified: lucene/dev/branches/branch_4x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/CHANGES.txt?rev=1547467&r1=1547466&r2=1547467&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/solr/CHANGES.txt Tue Dec 3 16:38:25 2013
@@ -187,6 +187,9 @@ Other Changes
* SOLR-5499: Log a warning if /get is not registered when using SolrCloud.
(Daniel Collins via shalin)
+* SOLR-5517: Return HTTP error on POST requests with no Content-Type.
+ (Ryan Ernst, Uwe Schindler)
+
================== 4.6.0 ==================
Versions of Major Components
Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/UpdateRequestHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/UpdateRequestHandler.java?rev=1547467&r1=1547466&r2=1547467&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/UpdateRequestHandler.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/UpdateRequestHandler.java Tue Dec 3 16:38:25 2013
@@ -75,7 +75,7 @@ public class UpdateRequestHandler extend
type = stream.getContentType();
}
if( type == null ) { // Normal requests will not get here.
- throw new SolrException(ErrorCode.BAD_REQUEST, "Missing ContentType");
+ throw new SolrException(ErrorCode.UNSUPPORTED_MEDIA_TYPE, "Missing ContentType");
}
int idx = type.indexOf(';');
if(idx>0) {
@@ -83,7 +83,7 @@ public class UpdateRequestHandler extend
}
ContentStreamLoader loader = loaders.get(type);
if(loader==null) {
- throw new SolrException(ErrorCode.BAD_REQUEST, "Unsupported ContentType: "
+ throw new SolrException(ErrorCode.UNSUPPORTED_MEDIA_TYPE, "Unsupported ContentType: "
+type+ " Not in: "+loaders.keySet());
}
if(loader.getDefaultWT()!=null) {
Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java?rev=1547467&r1=1547466&r2=1547467&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java Tue Dec 3 16:38:25 2013
@@ -18,16 +18,18 @@
package org.apache.solr.handler.component;
import org.apache.solr.common.SolrException;
+import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.ShardParams;
-import org.apache.solr.util.RTimer;
+import org.apache.solr.common.util.ContentStream;
import org.apache.solr.core.CloseHook;
import org.apache.solr.core.PluginInfo;
import org.apache.solr.core.SolrCore;
import org.apache.solr.handler.RequestHandlerBase;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
+import org.apache.solr.util.RTimer;
import org.apache.solr.util.SolrPluginUtils;
import org.apache.solr.util.plugin.PluginInfoInitialized;
import org.apache.solr.util.plugin.SolrCoreAware;
@@ -164,6 +166,10 @@ public class SearchHandler extends Reque
{
// int sleep = req.getParams().getInt("sleep",0);
// if (sleep > 0) {log.error("SLEEPING for " + sleep); Thread.sleep(sleep);}
+ if (req.getContentStreams() != null && req.getContentStreams().iterator().hasNext()) {
+ throw new SolrException(ErrorCode.BAD_REQUEST, "Search requests cannot accept content streams");
+ }
+
ResponseBuilder rb = new ResponseBuilder(req, rsp, components);
if (rb.requestInfo != null) {
rb.requestInfo.setResponseBuilder(rb);
Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java?rev=1547467&r1=1547466&r2=1547467&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java Tue Dec 3 16:38:25 2013
@@ -584,7 +584,7 @@ public class SolrRequestParsers
if (!isFormData(req)) {
throw new SolrException( ErrorCode.BAD_REQUEST, "Not application/x-www-form-urlencoded content: "+req.getContentType() );
}
-
+
final Map<String,String[]> map = new HashMap<String, String[]>();
// also add possible URL parameters and include into the map (parsed using UTF-8):
@@ -600,7 +600,7 @@ public class SolrRequestParsers
throw new SolrException(ErrorCode.BAD_REQUEST, "application/x-www-form-urlencoded content length (" +
totalLength + " bytes) exceeds upload limit of " + uploadLimitKB + " KB");
}
-
+
// get query String from request body, using the charset given in content-type:
final String cs = ContentStreamBase.getCharsetFromContentType(req.getContentType());
final Charset charset = (cs == null) ? IOUtils.CHARSET_UTF_8 : Charset.forName(cs);
@@ -680,7 +680,10 @@ public class SolrRequestParsers
if (ServletFileUpload.isMultipartContent(req)) {
return multipart.parseParamsAndFillStreams(req, streams);
}
- return raw.parseParamsAndFillStreams(req, streams);
+ if (req.getContentType() != null) {
+ return raw.parseParamsAndFillStreams(req, streams);
+ }
+ throw new SolrException(ErrorCode.UNSUPPORTED_MEDIA_TYPE, "Must specify a Content-Type header with POST requests");
}
throw new SolrException(ErrorCode.BAD_REQUEST, "Unsupported method: " + method + " for request " + req);
}
Modified: lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/request/TestRemoteStreaming.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/request/TestRemoteStreaming.java?rev=1547467&r1=1547466&r2=1547467&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/request/TestRemoteStreaming.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/request/TestRemoteStreaming.java Tue Dec 3 16:38:25 2013
@@ -27,6 +27,7 @@ import org.apache.solr.client.solrj.requ
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.SolrException.ErrorCode;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -103,14 +104,18 @@ public class TestRemoteStreaming extends
return null;
}
- /** Do a select query with the stream.url. Solr should NOT access that URL, and so the data should be there. */
+ /** Do a select query with the stream.url. Solr should fail */
@Test
public void testNoUrlAccess() throws Exception {
SolrQuery query = new SolrQuery();
query.setQuery( "*:*" );//for anything
query.add("stream.url",makeDeleteAllUrl());
- getSolrServer().query(query);
- assertTrue(searchFindsIt());//still there
+ try {
+ getSolrServer().query(query);
+ fail();
+ } catch (SolrException se) {
+ assertSame(ErrorCode.BAD_REQUEST, ErrorCode.getErrorCode(se.code()));
+ }
}
/** SOLR-3161
Modified: lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/servlet/SolrRequestParserTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/servlet/SolrRequestParserTest.java?rev=1547467&r1=1547466&r2=1547467&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/servlet/SolrRequestParserTest.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/servlet/SolrRequestParserTest.java Tue Dec 3 16:38:25 2013
@@ -379,4 +379,21 @@ public class SolrRequestParserTest exten
assertEquals("10.0.0.1", ((HttpServletRequest)solrReq.getContext().get("httpRequest")).getHeaders("X-Forwarded-For").nextElement());
}
+
+ public void testPostMissingContentType() throws Exception {
+ HttpServletRequest request = createMock(HttpServletRequest.class);
+ expect(request.getMethod()).andReturn("POST").anyTimes();
+ expect(request.getContentType()).andReturn(null).anyTimes();
+ expect(request.getQueryString()).andReturn(null).anyTimes();
+ replay(request);
+
+ SolrRequestParsers parsers = new SolrRequestParsers(h.getCore().getSolrConfig());
+ try {
+ parsers.parse(h.getCore(), "/select", request);
+ fail("should throw SolrException");
+ } catch (SolrException e) {
+ assertTrue(e.getMessage().startsWith("Must specify a Content-Type header with POST requests"));
+ assertEquals(415, e.code());
+ }
+ }
}
Modified: lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/SolrException.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/SolrException.java?rev=1547467&r1=1547466&r2=1547467&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/SolrException.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/SolrException.java Tue Dec 3 16:38:25 2013
@@ -42,6 +42,7 @@ public class SolrException extends Runti
FORBIDDEN( 403 ),
NOT_FOUND( 404 ),
CONFLICT( 409 ),
+ UNSUPPORTED_MEDIA_TYPE( 415 ),
SERVER_ERROR( 500 ),
SERVICE_UNAVAILABLE( 503 ),
UNKNOWN(0);