Description
Followup of SOLR-4265:
SOLR-4265 has 2 problems:
- it reads the whole InputStream into a String and this one can be big. This wastes memory, especially when your query string from the POSted form data is near the 2 Megabyte limit. The String is then packed in splitted form into a big Map.
- it does not report corrupt UTF-8
The attached patch will do 2 things:
- The decoding of the POSTed form data is done on the ServletInputStream, directly parsing the bytes (not chars). Key/Value pairs are extracted and %-decoded to byte[] on the fly. URL-parameters from getQueryString() are parsed with the same code using ByteArrayInputStream on the original String, interpreted as UTF-8 (this is a hack, because Servlet API does not give back the original bytes from the HTTP request). To be standards conform, the query String should be interpreted as US-ASCII, but with this approach, not full escaped UTF-8 from the HTTP request survive.
- the byte[] key/value pairs are converted to Strings using CharsetDecoder
This will be memory efficient and will report incorrect escaped form data, so people will no longer complain if searches hit no results or similar.