use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.
the class HttpOutputTest method testAsyncWriteSmall.
@Test
public void testAsyncWriteSmall() throws Exception {
final Resource big = Resource.newClassPathResource("simple/big.txt");
_handler._writeLengthIfKnown = false;
_handler._content = BufferUtil.toBuffer(big, false);
_handler._arrayBuffer = new byte[8];
_handler._async = true;
String response = _connector.getResponse("GET / HTTP/1.0\nHost: localhost:80\n\n");
assertThat(response, containsString("HTTP/1.1 200 OK"));
assertThat(response, Matchers.not(containsString("Content-Length")));
assertThat(response, endsWith(toUTF8String(big)));
}
use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.
the class HttpOutputTest method testWriteMed.
@Test
public void testWriteMed() throws Exception {
final Resource big = Resource.newClassPathResource("simple/big.txt");
_handler._writeLengthIfKnown = false;
_handler._content = BufferUtil.toBuffer(big, false);
_handler._arrayBuffer = new byte[4000];
String response = _connector.getResponse("GET / HTTP/1.0\nHost: localhost:80\n\n");
assertThat(response, containsString("HTTP/1.1 200 OK"));
assertThat(response, Matchers.not(containsString("Content-Length")));
assertThat(response, endsWith(toUTF8String(big)));
}
use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.
the class HttpOutputTest method testSendChannelBigChunked.
@Test
public void testSendChannelBigChunked() throws Exception {
Resource big = Resource.newClassPathResource("simple/big.txt");
final ReadableByteChannel channel = big.getReadableByteChannel();
_handler._contentChannel = new ReadableByteChannel() {
@Override
public boolean isOpen() {
return channel.isOpen();
}
@Override
public void close() throws IOException {
channel.close();
}
@Override
public int read(ByteBuffer dst) throws IOException {
int filled = 0;
if (dst.position() == 0 && dst.limit() > 2000) {
int limit = dst.limit();
dst.limit(2000);
filled = channel.read(dst);
dst.limit(limit);
} else
filled = channel.read(dst);
return filled;
}
};
LocalEndPoint endp = _connector.executeRequest("GET / HTTP/1.1\nHost: localhost:80\n\n" + "GET / HTTP/1.1\nHost: localhost:80\nConnection: close\n\n");
String response = endp.getResponse();
assertThat(response, containsString("HTTP/1.1 200 OK"));
assertThat(response, containsString("Transfer-Encoding: chunked"));
assertThat(response, containsString("1\tThis is a big file"));
assertThat(response, containsString("400\tThis is a big file"));
assertThat(response, containsString("\r\n0\r\n"));
response = endp.getResponse();
assertThat(response, containsString("HTTP/1.1 200 OK"));
assertThat(response, containsString("Connection: close"));
}
use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.
the class HttpOutputTest method testAsyncWriteBufferLargeDirect.
@Test
public void testAsyncWriteBufferLargeDirect() throws Exception {
final Resource big = Resource.newClassPathResource("simple/big.txt");
_handler._writeLengthIfKnown = false;
_handler._content = BufferUtil.toBuffer(big, true);
_handler._byteBuffer = BufferUtil.allocateDirect(8192);
_handler._async = true;
String response = _connector.getResponses("GET / HTTP/1.0\nHost: localhost:80\n\n");
assertThat(response, containsString("HTTP/1.1 200 OK"));
assertThat(response, Matchers.not(containsString("Content-Length")));
assertThat(response, endsWith(toUTF8String(big)));
}
use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.
the class HttpOutputTest method testAsyncWriteBufferSmall.
@Test
public void testAsyncWriteBufferSmall() throws Exception {
final Resource big = Resource.newClassPathResource("simple/big.txt");
_handler._writeLengthIfKnown = false;
_handler._content = BufferUtil.toBuffer(big, false);
_handler._byteBuffer = BufferUtil.allocate(8);
_handler._async = true;
String response = _connector.getResponse("GET / HTTP/1.0\nHost: localhost:80\n\n");
assertThat(response, containsString("HTTP/1.1 200 OK"));
assertThat(response, Matchers.not(containsString("Content-Length")));
assertThat(response, endsWith(toUTF8String(big)));
}
Aggregations