use of org.apache.hc.core5.http.message.BufferedHeader in project httpcomponents-core by apache.
the class TestBufferedHeader method testBasicConstructor.
@Test
public void testBasicConstructor() throws Exception {
final CharArrayBuffer buf = new CharArrayBuffer(32);
buf.append("name: value");
final BufferedHeader header = new BufferedHeader(buf, false);
Assertions.assertEquals("name", header.getName());
Assertions.assertEquals("value", header.getValue());
Assertions.assertSame(buf, header.getBuffer());
Assertions.assertEquals(5, header.getValuePos());
}
use of org.apache.hc.core5.http.message.BufferedHeader in project httpcomponents-core by apache.
the class TestBufferedHeader method testSerialization.
@Test
public void testSerialization() throws Exception {
final CharArrayBuffer buf = new CharArrayBuffer(32);
buf.append("name: value");
final BufferedHeader orig = new BufferedHeader(buf, false);
final ByteArrayOutputStream outbuffer = new ByteArrayOutputStream();
final ObjectOutputStream outStream = new ObjectOutputStream(outbuffer);
outStream.writeObject(orig);
outStream.close();
final byte[] raw = outbuffer.toByteArray();
final ByteArrayInputStream inBuffer = new ByteArrayInputStream(raw);
final ObjectInputStream inStream = new ObjectInputStream(inBuffer);
final BufferedHeader clone = (BufferedHeader) inStream.readObject();
Assertions.assertEquals(orig.getName(), clone.getName());
Assertions.assertEquals(orig.getValue(), clone.getValue());
}
use of org.apache.hc.core5.http.message.BufferedHeader in project httpcomponents-core by apache.
the class TestBufferedHeader method testInvalidHeaderParsing.
@Test
public void testInvalidHeaderParsing() throws Exception {
final CharArrayBuffer buf = new CharArrayBuffer(16);
buf.clear();
buf.append("");
Assertions.assertThrows(ParseException.class, () -> new BufferedHeader(buf, false));
buf.clear();
buf.append("blah");
Assertions.assertThrows(ParseException.class, () -> new BufferedHeader(buf, false));
buf.clear();
buf.append(":");
Assertions.assertThrows(ParseException.class, () -> new BufferedHeader(buf, false));
buf.clear();
buf.append(" :");
Assertions.assertThrows(ParseException.class, () -> new BufferedHeader(buf, false));
buf.clear();
buf.append(": blah");
Assertions.assertThrows(ParseException.class, () -> new BufferedHeader(buf, false));
buf.clear();
buf.append(" : blah");
Assertions.assertThrows(ParseException.class, () -> new BufferedHeader(buf, false));
buf.clear();
buf.append("header : blah");
Assertions.assertThrows(ParseException.class, () -> new BufferedHeader(buf, true));
}
use of org.apache.hc.core5.http.message.BufferedHeader in project httpcomponents-core by apache.
the class ChunkDecoder method processFooters.
private void processFooters() throws IOException {
final int count = this.trailerBufs.size();
if (count > 0) {
this.trailers.clear();
for (int i = 0; i < this.trailerBufs.size(); i++) {
try {
this.trailers.add(new BufferedHeader(this.trailerBufs.get(i)));
} catch (final ParseException ex) {
throw new IOException(ex);
}
}
}
this.trailerBufs.clear();
}
Aggregations