if (s.startsWith("/?n=")) {
s = s.substring(4);
try {
n = Integer.parseInt(s);
if (n <= 0) {
throw new HttpException("Invalid request: " +
"number of repetitions cannot be negative or zero");
}
} catch (NumberFormatException ex) {
throw new HttpException("Invalid request: " +
"number of repetitions is invalid");
}
}
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");
}
}
});