Search in sources :

Example 1 with MimeMappings

use of cn.taketoday.framework.web.server.MimeMappings in project today-framework by TAKETODAY.

the class AbstractServletWebServerFactoryTests method mimeType.

@Test
void mimeType() throws Exception {
    FileCopyUtils.copy("test", new FileWriter(new File(this.tempDir, "test.xxcss")));
    AbstractServletWebServerFactory factory = getFactory();
    factory.setRegisterDefaultServlet(true);
    factory.setDocumentRoot(this.tempDir);
    MimeMappings mimeMappings = new MimeMappings();
    mimeMappings.add("xxcss", "text/css");
    factory.setMimeMappings(mimeMappings);
    this.webServer = factory.getWebServer();
    this.webServer.start();
    ClientHttpResponse response = getClientResponse(getLocalUrl("/test.xxcss"));
    assertThat(response.getHeaders().getContentType().toString()).isEqualTo("text/css");
    response.close();
}
Also used : FileWriter(java.io.FileWriter) MimeMappings(cn.taketoday.framework.web.server.MimeMappings) File(java.io.File) ClientHttpResponse(cn.taketoday.http.client.ClientHttpResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 2 with MimeMappings

use of cn.taketoday.framework.web.server.MimeMappings in project today-infrastructure by TAKETODAY.

the class AbstractServletWebServerFactoryTests method mimeType.

@Test
void mimeType() throws Exception {
    FileCopyUtils.copy("test", new FileWriter(new File(this.tempDir, "test.xxcss")));
    AbstractServletWebServerFactory factory = getFactory();
    factory.setRegisterDefaultServlet(true);
    factory.setDocumentRoot(this.tempDir);
    MimeMappings mimeMappings = new MimeMappings();
    mimeMappings.add("xxcss", "text/css");
    factory.setMimeMappings(mimeMappings);
    this.webServer = factory.getWebServer();
    this.webServer.start();
    ClientHttpResponse response = getClientResponse(getLocalUrl("/test.xxcss"));
    assertThat(response.getHeaders().getContentType().toString()).isEqualTo("text/css");
    response.close();
}
Also used : FileWriter(java.io.FileWriter) MimeMappings(cn.taketoday.framework.web.server.MimeMappings) File(java.io.File) ClientHttpResponse(cn.taketoday.http.client.ClientHttpResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

MimeMappings (cn.taketoday.framework.web.server.MimeMappings)2 ClientHttpResponse (cn.taketoday.http.client.ClientHttpResponse)2 File (java.io.File)2 FileWriter (java.io.FileWriter)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2