use of cn.taketoday.framework.web.server.Compression in project today-infrastructure by TAKETODAY.
the class AbstractServletWebServerFactoryTests method setUpFactoryForCompression.
private String setUpFactoryForCompression(int contentSize, String[] mimeTypes, String[] excludedUserAgents) {
char[] chars = new char[contentSize];
Arrays.fill(chars, 'F');
String testContent = new String(chars);
AbstractServletWebServerFactory factory = getFactory();
Compression compression = new Compression();
compression.setEnabled(true);
if (mimeTypes != null) {
compression.setMimeTypes(mimeTypes);
}
if (excludedUserAgents != null) {
compression.setExcludedUserAgents(excludedUserAgents);
}
factory.setCompression(compression);
factory.addInitializers(new ServletRegistrationBean<HttpServlet>(new HttpServlet() {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setContentType("text/plain");
resp.setContentLength(testContent.length());
resp.getWriter().write(testContent);
resp.getWriter().flush();
}
}, "/test.txt"));
this.webServer = factory.getWebServer();
this.webServer.start();
return testContent;
}
use of cn.taketoday.framework.web.server.Compression in project today-infrastructure by TAKETODAY.
the class AbstractReactiveWebServerFactoryTests method noCompressionForResponseWithInvalidContentType.
@Test
void noCompressionForResponseWithInvalidContentType() {
Compression compression = new Compression();
compression.setEnabled(true);
compression.setMimeTypes(new String[] { "application/json" });
WebClient client = prepareCompressionTest(compression, "test~plain");
ResponseEntity<Void> response = client.get().retrieve().toBodilessEntity().block(Duration.ofSeconds(30));
assertResponseIsNotCompressed(response);
}
use of cn.taketoday.framework.web.server.Compression in project today-infrastructure by TAKETODAY.
the class AbstractReactiveWebServerFactoryTests method prepareCompressionTest.
protected WebClient prepareCompressionTest() {
Compression compression = new Compression();
compression.setEnabled(true);
return prepareCompressionTest(compression);
}
use of cn.taketoday.framework.web.server.Compression in project today-infrastructure by TAKETODAY.
the class AbstractReactiveWebServerFactoryTests method noCompressionForSmallResponse.
@Test
void noCompressionForSmallResponse() {
Compression compression = new Compression();
compression.setEnabled(true);
compression.setMinResponseSize(DataSize.ofBytes(3001));
WebClient client = prepareCompressionTest(compression);
ResponseEntity<Void> response = client.get().retrieve().toBodilessEntity().block(Duration.ofSeconds(30));
assertResponseIsNotCompressed(response);
}
use of cn.taketoday.framework.web.server.Compression in project today-framework by TAKETODAY.
the class AbstractReactiveWebServerFactoryTests method noCompressionForMimeType.
@Test
void noCompressionForMimeType() {
Compression compression = new Compression();
compression.setEnabled(true);
compression.setMimeTypes(new String[] { "application/json" });
WebClient client = prepareCompressionTest(compression);
ResponseEntity<Void> response = client.get().retrieve().toBodilessEntity().block(Duration.ofSeconds(30));
assertResponseIsNotCompressed(response);
}
Aggregations