@Override public String toString() { return this.buffer.toString(); }
@Override public String toString() { return this.buffer.toString(); }
@Override public String generateContent() { return content.toString(); }
@Override protected ClassicHttpResponse createMessage(final CharArrayBuffer buffer) throws IOException { try { return super.createMessage(buffer); } catch (final HttpException ex) { if (this.log.isDebugEnabled()) { this.log.debug("Garbage in response: " + buffer.toString()); } return null; } }
@Test public void testMalformedInputActionReplace() throws Exception { final byte[] tmp = constructString(SWISS_GERMAN_HELLO).getBytes(StandardCharsets.ISO_8859_1); final CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder(); decoder.onMalformedInput(CodingErrorAction.REPLACE); decoder.onUnmappableCharacter(CodingErrorAction.IGNORE); final SessionInputBuffer inBuffer = new SessionInputBufferImpl(16, decoder); final ByteArrayInputStream inputStream = new ByteArrayInputStream(tmp); final CharArrayBuffer chbuffer = new CharArrayBuffer(32); inBuffer.readLine(chbuffer, inputStream); Assert.assertEquals("Gr\ufffdezi_z\ufffdm\ufffd", chbuffer.toString()); }
@Test public void testMalformedInputActionIgnore() throws Exception { final byte[] tmp = constructString(SWISS_GERMAN_HELLO).getBytes(StandardCharsets.ISO_8859_1); final CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder(); decoder.onMalformedInput(CodingErrorAction.IGNORE); decoder.onUnmappableCharacter(CodingErrorAction.IGNORE); final SessionInputBuffer inBuffer = new SessionInputBufferImpl(16, decoder); final ByteArrayInputStream inputStream = new ByteArrayInputStream(tmp); final CharArrayBuffer chbuffer = new CharArrayBuffer(32); inBuffer.readLine(chbuffer, inputStream); Assert.assertEquals("Grezi_zm", chbuffer.toString()); }
@Test public void testAppendAsciiByteArray() throws Exception { final String s1 = "stuff"; final String s2 = " and more stuff"; final byte[] b1 = s1.getBytes(StandardCharsets.US_ASCII); final byte[] b2 = s2.getBytes(StandardCharsets.US_ASCII); final CharArrayBuffer buffer = new CharArrayBuffer(8); buffer.append(b1, 0, b1.length); buffer.append(b2, 0, b2.length); Assert.assertEquals("stuff and more stuff", buffer.toString()); }
@Test //HTTPCORE-472 public void testLineLimit3() throws Exception { final String s = "012345678\r\nblaaaaaaaaaaaaaaaaaah"; final byte[] tmp = s.getBytes(StandardCharsets.US_ASCII); final SessionInputBuffer inBuffer1 = new SessionInputBufferImpl(128); final ByteArrayInputStream inputStream = new ByteArrayInputStream(tmp); final CharArrayBuffer chbuffer = new CharArrayBuffer(16); inBuffer1.readLine(chbuffer, inputStream); Assert.assertEquals("012345678", chbuffer.toString()); }
@Test public void testAppendNullString() throws Exception { final CharArrayBuffer buffer = new CharArrayBuffer(8); buffer.append((String)null); Assert.assertEquals("null", buffer.toString()); }
@Test public void testAppendNullByteArrayBuffer() throws Exception { final CharArrayBuffer buffer = new CharArrayBuffer(8); buffer.append((ByteArrayBuffer)null, 0, 0); Assert.assertEquals("", buffer.toString()); }
@Test public void testAppendNullByteArray() throws Exception { final CharArrayBuffer buffer = new CharArrayBuffer(8); buffer.append((byte[])null, 0, 0); Assert.assertEquals("", buffer.toString()); }
@Test public void testHttpVersionFormatting() throws Exception { final CharArrayBuffer buf = new CharArrayBuffer(64); this.formatter.formatProtocolVersion(buf, HttpVersion.HTTP_1_1); Assert.assertEquals("HTTP/1.1", buf.toString()); }
@Test public void testHeaderFormattingRequestSplitting() throws Exception { final CharArrayBuffer buf = new CharArrayBuffer(64); final Header header = new BasicHeader("Host", "apache.org\r\nOops: oops"); formatter.formatHeader(buf, header); final String s = buf.toString(); Assert.assertFalse(s.contains("\n")); Assert.assertEquals("Host: apache.org Oops: oops", s); } }
@Test public void testHeaderFormatting() throws Exception { final CharArrayBuffer buf = new CharArrayBuffer(64); final Header header1 = new BasicHeader("name", "value"); this.formatter.formatHeader(buf, header1); Assert.assertEquals("name: value", buf.toString()); buf.clear(); final Header header2 = new BasicHeader("name", null); this.formatter.formatHeader(buf, header2); Assert.assertEquals("name: ", buf.toString()); }
@Test public void testSLFormatting() throws Exception { final CharArrayBuffer buf = new CharArrayBuffer(64); final StatusLine statusline1 = new StatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK"); this.formatter.formatStatusLine(buf, statusline1); Assert.assertEquals("HTTP/1.1 200 OK", buf.toString()); buf.clear(); final StatusLine statusline2 = new StatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, null); this.formatter.formatStatusLine(buf, statusline2); Assert.assertEquals("HTTP/1.1 200 ", buf.toString()); // see "testSLParseSuccess" in TestBasicLineParser: // trailing space is correct }
@Test public void testAppendString() throws Exception { final CharArrayBuffer buffer = new CharArrayBuffer(8); buffer.append("stuff"); buffer.append(" and more stuff"); Assert.assertEquals("stuff and more stuff", buffer.toString()); }
@Test public void testAppendNullCharArrayBuffer() throws Exception { final CharArrayBuffer buffer = new CharArrayBuffer(8); buffer.append((CharArrayBuffer)null); buffer.append((CharArrayBuffer)null, 0, 0); Assert.assertEquals("", buffer.toString()); }
@Test public void testRLFormatting() throws Exception { final RequestLine requestline = new RequestLine("GET", "/stuff", HttpVersion.HTTP_1_1); final CharArrayBuffer buf = new CharArrayBuffer(64); this.formatter.formatRequestLine(buf, requestline); Assert.assertEquals("GET /stuff HTTP/1.1", buf.toString()); }
@Test public void testAppendCharArrayBuffer() throws Exception { final CharArrayBuffer buffer1 = new CharArrayBuffer(8); buffer1.append(" and more stuff"); final CharArrayBuffer buffer2 = new CharArrayBuffer(8); buffer2.append("stuff"); buffer2.append(buffer1); Assert.assertEquals("stuff and more stuff", buffer2.toString()); }
@Test public void testAppendSingleChar() throws Exception { final CharArrayBuffer buffer = new CharArrayBuffer(4); buffer.append('1'); buffer.append('2'); buffer.append('3'); buffer.append('4'); buffer.append('5'); buffer.append('6'); Assert.assertEquals("123456", buffer.toString()); }