use of org.eclipse.jetty.util.Utf8StringBuilder in project jetty.project by eclipse.
the class ForwardProxyServerTest method testRequestTarget.
@Test
public void testRequestTarget() throws Exception {
startServer(new AbstractConnectionFactory("http/1.1") {
@Override
public Connection newConnection(Connector connector, EndPoint endPoint) {
return new AbstractConnection(endPoint, connector.getExecutor()) {
@Override
public void onOpen() {
super.onOpen();
fillInterested();
}
@Override
public void onFillable() {
try {
// When using TLS, multiple reads are required.
ByteBuffer buffer = BufferUtil.allocate(1024);
int filled = 0;
while (filled == 0) filled = getEndPoint().fill(buffer);
Utf8StringBuilder builder = new Utf8StringBuilder();
builder.append(buffer);
String request = builder.toString();
// ProxyServlet will receive an absolute URI from
// the client, and convert it to a relative URI.
// The ConnectHandler won't modify what the client
// sent, which must be a relative URI.
Assert.assertThat(request.length(), Matchers.greaterThan(0));
if (serverSslContextFactory == null)
Assert.assertFalse(request.contains("http://"));
else
Assert.assertFalse(request.contains("https://"));
String response = "" + "HTTP/1.1 200 OK\r\n" + "Content-Length: 0\r\n" + "\r\n";
getEndPoint().write(Callback.NOOP, ByteBuffer.wrap(response.getBytes(StandardCharsets.UTF_8)));
} catch (Throwable x) {
x.printStackTrace();
close();
}
}
};
}
});
startProxy();
HttpClient httpClient = new HttpClient(newSslContextFactory());
httpClient.getProxyConfiguration().getProxies().add(newHttpProxy());
httpClient.start();
try {
ContentResponse response = httpClient.newRequest("localhost", serverConnector.getLocalPort()).scheme(serverSslContextFactory == null ? "http" : "https").method(HttpMethod.GET).path("/test").send();
Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
} finally {
httpClient.stop();
}
}
use of org.eclipse.jetty.util.Utf8StringBuilder in project jetty.project by eclipse.
the class HttpWriterTest method testNotCESU8.
@Test
public void testNotCESU8() throws Exception {
HttpWriter _writer = new Utf8HttpWriter(_httpOut);
String data = "xxx𐐀xxx";
_writer.write(data);
assertEquals("787878F0909080787878", TypeUtil.toHexString(BufferUtil.toArray(_bytes)));
assertArrayEquals(data.getBytes(StandardCharsets.UTF_8), BufferUtil.toArray(_bytes));
assertEquals(3 + 4 + 3, _bytes.remaining());
Utf8StringBuilder buf = new Utf8StringBuilder();
buf.append(BufferUtil.toArray(_bytes), 0, _bytes.remaining());
assertEquals(data, buf.toString());
}
use of org.eclipse.jetty.util.Utf8StringBuilder in project jetty.project by eclipse.
the class SniSslConnectionFactoryTest method response.
private String response(InputStream input) throws IOException {
Utf8StringBuilder buffer = new Utf8StringBuilder();
int crlfs = 0;
while (true) {
int read = input.read();
Assert.assertTrue(read >= 0);
buffer.append((byte) read);
crlfs = (read == '\r' || read == '\n') ? crlfs + 1 : 0;
if (crlfs == 4)
break;
}
return buffer.toString();
}
use of org.eclipse.jetty.util.Utf8StringBuilder in project jetty.project by eclipse.
the class WebSocketServletRFCTest method testDetectBadUTF8.
@Test(expected = NotUtf8Exception.class)
public void testDetectBadUTF8() {
byte[] buf = new byte[] { (byte) 0xC2, (byte) 0xC3 };
Utf8StringBuilder utf = new Utf8StringBuilder();
utf.append(buf, 0, buf.length);
}
use of org.eclipse.jetty.util.Utf8StringBuilder in project i2p.i2p by i2p.
the class I2PRequestLog method doStart.
/* ------------------------------------------------------------ */
protected void doStart() throws Exception {
if (_logDateFormat != null) {
_logDateCache = new DateCache(_logDateFormat, _logLocale, _logTimeZone);
}
if (_filename != null) {
_fileOut = new RolloverFileOutputStream(_filename, _append, _retainDays, TimeZone.getTimeZone(_logTimeZone), _filenameDateFormat, null);
_closeOut = true;
Log.getLogger((String) null).info("Opened " + getDatedFilename());
} else
_fileOut = System.err;
_out = _fileOut;
if (_ignorePaths != null && _ignorePaths.length > 0) {
_ignorePathMap = new PathMap<String>();
for (int i = 0; i < _ignorePaths.length; i++) _ignorePathMap.put(_ignorePaths[i], _ignorePaths[i]);
} else
_ignorePathMap = null;
_writer = new OutputStreamWriter(_out, "UTF-8");
_buffers = new ArrayList<Utf8StringBuilder>();
_copy = new char[1024];
super.doStart();
}
Aggregations