Search in sources :

Example 1 with BufferedHeader

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());
}
Also used : CharArrayBuffer(org.apache.hc.core5.util.CharArrayBuffer) Test(org.junit.jupiter.api.Test)

Example 2 with BufferedHeader

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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CharArrayBuffer(org.apache.hc.core5.util.CharArrayBuffer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.jupiter.api.Test)

Example 3 with BufferedHeader

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));
}
Also used : CharArrayBuffer(org.apache.hc.core5.util.CharArrayBuffer) Test(org.junit.jupiter.api.Test)

Example 4 with BufferedHeader

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();
}
Also used : BufferedHeader(org.apache.hc.core5.http.message.BufferedHeader) ParseException(org.apache.hc.core5.http.ParseException) IOException(java.io.IOException)

Aggregations

CharArrayBuffer (org.apache.hc.core5.util.CharArrayBuffer)3 Test (org.junit.jupiter.api.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 ParseException (org.apache.hc.core5.http.ParseException)1 BufferedHeader (org.apache.hc.core5.http.message.BufferedHeader)1