[OLINGO-1499]Fix case-sensitive handling of Content-Type header in BatchLineReader
This commit is contained in:
parent
dadeed6ef6
commit
8bd229b40e
|
@ -24,6 +24,7 @@ import java.nio.ByteBuffer;
|
|||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||
|
@ -95,7 +96,7 @@ public class BatchLineReader {
|
|||
|
||||
private void updateCurrentCharset(final String currentLine) {
|
||||
if (currentLine != null) {
|
||||
if (currentLine.startsWith(HttpHeader.CONTENT_TYPE)) {
|
||||
if (currentLine.toLowerCase(Locale.ENGLISH).startsWith(HttpHeader.CONTENT_TYPE.toLowerCase(Locale.ENGLISH))) {
|
||||
int cutOff = currentLine.endsWith(CRLF) ? 2 : currentLine.endsWith(LFS) ? 1 : 0;
|
||||
final ContentType contentType = ContentType.parse(
|
||||
currentLine.substring(HttpHeader.CONTENT_TYPE.length() + 1, currentLine.length() - cutOff).trim());
|
||||
|
|
|
@ -270,6 +270,21 @@ public class BatchLineReaderTest {
|
|||
reader.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void specialCharactersInJsonWithLowercaseContentType() throws Exception {
|
||||
final String text = "\n"
|
||||
+ "content-type: application/json\n"
|
||||
+ "\n"
|
||||
+ "{\"text\": \"ä€ß\"}\n";
|
||||
BatchLineReader reader = create(text);
|
||||
reader.readLine();
|
||||
reader.readLine();
|
||||
reader.readLine();
|
||||
assertEquals("{\"text\": \"ä€ß\"}\n", reader.readLine());
|
||||
assertNull(reader.readLine());
|
||||
reader.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rawBytes() throws Exception {
|
||||
byte[] content = new byte[Byte.MAX_VALUE - Byte.MIN_VALUE + 1];
|
||||
|
|
Loading…
Reference in New Issue