Skip to content

Commit 31cbc86

Browse files
committed
✅ Add tests for pipelining requests
1 parent 9810faa commit 31cbc86

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

test/freenet/clients/http/ToadletContextImplTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,33 @@ public void putRequestToToadletThatDoesNotSupportPutResultsInHttpStatus405() thr
297297
assertThat(parse(outputStream.toByteArray()), contains(hasStatus(equalTo(405), equalTo("Method Not Allowed"))));
298298
}
299299

300+
@Test
301+
public void pipeliningTwoGetRequestsWithPersistentConnectionsEnabledResultsInTwoHttpStatus200() throws Exception {
302+
setupInputStream("GET / HTTP/1.1\r\n\r\nGET / HTTP/1.1\r\n\r\n");
303+
when(toadletContainer.enablePersistentConnections()).thenReturn(true);
304+
when(toadletContainer.findToadlet(any())).thenReturn(homepageToadlet);
305+
ToadletContextImpl.handle(socket, toadletContainer, pageMaker, null, null);
306+
assertThat(parse(outputStream.toByteArray()), contains(
307+
allOf(hasStatus(200), hasBody(equalTo("GET OK\n".getBytes(UTF_8)))),
308+
allOf(hasStatus(200), hasBody(equalTo("GET OK\n".getBytes(UTF_8))))
309+
));
310+
}
311+
312+
@Test
313+
public void pipeliningAPutAndAGetRequestResultsInTwoSuccessfulRequests() throws Exception {
314+
setupInputStream("POST /post-request HTTP/1.1\r\nContent-Length: 0\r\n\r\nGET /get-request HTTP/1.1\r\n\r\n");
315+
when(toadletContainer.enablePersistentConnections()).thenReturn(true);
316+
when(toadletContainer.allowPosts()).thenReturn(true);
317+
postToadlet.allowPostWithoutPassword();
318+
when(toadletContainer.findToadlet(new URI("/post-request"))).thenReturn(postToadlet);
319+
when(toadletContainer.findToadlet(new URI("/get-request"))).thenReturn(homepageToadlet);
320+
ToadletContextImpl.handle(socket, toadletContainer, pageMaker, null, null);
321+
assertThat(parse(outputStream.toByteArray()), contains(
322+
allOf(hasStatus(200), hasBody(equalTo("POST OK\n".getBytes(UTF_8)))),
323+
allOf(hasStatus(200), hasBody(equalTo("GET OK\n".getBytes(UTF_8))))
324+
));
325+
}
326+
300327
private void setupInputStream(String request) throws IOException {
301328
when(socket.getInputStream()).thenReturn(new ByteArrayInputStream(request.getBytes(UTF_8)));
302329
}

0 commit comments

Comments
 (0)