}
}
HttpEntity incoming = ((HttpEntityEnclosingRequest) request).getEntity();
String line = EntityUtils.toString(incoming);
ContentType contentType = ContentType.getOrDefault(incoming);
String charset = contentType.getCharset();
if (charset == null) {
charset = HTTP.DEFAULT_CONTENT_CHARSET;
}
RepeatingEntity outgoing = new RepeatingEntity(line, charset, n);
outgoing.setChunked(n % 2 == 0);
response.setEntity(outgoing);
} else {
throw new HttpException("Invalid request: POST request expected");
}
}
});
this.server.start();
DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
HttpHost host = new HttpHost("localhost", this.server.getPort());
try {
for (int i = 0; i < patterns.length; i++) {
String pattern = patterns[i];
for (int n = 1000; n < 1020; n++) {
if (!conn.isOpen()) {
Socket socket = new Socket(host.getHostName(), host.getPort());
conn.bind(socket, this.client.getParams());
}
BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest(
"POST", "/?n=" + n);
StringEntity outgoing = new StringEntity(pattern);
outgoing.setChunked(n % 2 == 0);
post.setEntity(outgoing);
HttpResponse response = this.client.execute(post, host, conn);
HttpEntity incoming = response.getEntity();
Assert.assertNotNull(incoming);
InputStream instream = incoming.getContent();
ContentType contentType = ContentType.getOrDefault(incoming);
String charset = contentType.getCharset();
if (charset == null) {
charset = HTTP.DEFAULT_CONTENT_CHARSET;
}
Assert.assertNotNull(instream);
BufferedReader reader = new BufferedReader(new InputStreamReader(instream, charset));