public String asString(String charset) throws IOException { byte[] bytes = asBytes(); return new String(bytes, charset); }
public String asString(String charset) throws IOException { byte[] bytes = asBytes(); return new String(bytes, charset); }
byte[] bytes = makeRequest("/say/helloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo?gzip=true").get().asBytes(); Assert.assertNotEquals("I say: helloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo", new String(bytes));
Assert.assertArrayEquals(test, makeRequest("/") .header("Range", "bytes=0-99") .get().asBytes()); .get().asBytes()); Assert.assertArrayEquals(test, makeRequest("/") .header("Range", "bytes=100-") .get().asBytes()); Assert.assertArrayEquals(test, makeRequest("/") .header("Range", "bytes=-200") .get().asBytes()); Assert.assertArrayEquals(test, makeRequest("/") .header("Range", "bytes=800-2000") .get().asBytes());
@Test public void test_lazy_writing() { byte[] data = new byte[20 * 1024 * 1024]; ThreadLocalRandom.current().nextBytes(data); handler = new UrlHandler() .append("/", (request, response) -> response.setBody(data)); HttpServer<ObservedConnection> proxy = new HttpServer<ObservedConnection>(null, port + 1, context, 0) { @Override protected ObservedConnection createConnection(int fd, int ip, int port) { return new ObservedConnection(fd, ip, port, this); } }; proxy.getUrlMapping() .append("/", new ProxyHandler("localhost", port)); proxy.setIoThreadsCount(1); proxy.start(); try { Thread.sleep(25); Assert.assertArrayEquals(data, makeRequest("/").header("Connection", "Close").get().asBytes()); writeSocket(data, 0); writeSocket(data, 10); } catch (Exception e) { e.printStackTrace(); assert false; } finally { proxy.close(); } }