use of cn.taketoday.http.client.ClientHttpResponse 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();
}
use of cn.taketoday.http.client.ClientHttpResponse in project today-framework by TAKETODAY.
the class AbstractServletWebServerFactoryTests method serverHeaderCanBeCustomizedWhenUsingSsl.
@Test
void serverHeaderCanBeCustomizedWhenUsingSsl() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
factory.setServerHeader("MyServer");
factory.setSsl(getSsl(null, "password", "src/test/resources/test.jks"));
this.webServer = factory.getWebServer(new ServletRegistrationBean<>(new ExampleServlet(true, false), "/hello"));
this.webServer.start();
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());
HttpClient httpClient = this.httpClientBuilder.get().setSSLSocketFactory(socketFactory).setRetryHandler(new DefaultHttpRequestRetryHandler(10, false)).build();
ClientHttpResponse response = getClientResponse(getLocalUrl("https", "/hello"), HttpMethod.GET, new HttpComponentsClientHttpRequestFactory(httpClient));
assertThat(response.getHeaders().get("Server")).containsExactly("MyServer");
}
use of cn.taketoday.http.client.ClientHttpResponse in project today-framework by TAKETODAY.
the class AbstractServletWebServerFactoryTests method cookieSameSiteSuppliers.
@Test
void cookieSameSiteSuppliers() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
factory.addCookieSameSiteSuppliers(CookieSameSiteSupplier.ofLax().whenHasName("relaxed"));
factory.addCookieSameSiteSuppliers(CookieSameSiteSupplier.ofNone().whenHasName("empty"));
factory.addCookieSameSiteSuppliers(CookieSameSiteSupplier.ofStrict().whenHasName("controlled"));
factory.addInitializers(new ServletRegistrationBean<>(new CookieServlet(true), "/"));
this.webServer = factory.getWebServer();
this.webServer.start();
ClientHttpResponse clientResponse = getClientResponse(getLocalUrl("/"));
List<String> setCookieHeaders = clientResponse.getHeaders().get("Set-Cookie");
assertThat(setCookieHeaders).satisfiesExactlyInAnyOrder((header) -> assertThat(header).contains("JSESSIONID").doesNotContain("SameSite"), (header) -> assertThat(header).contains("test=test").doesNotContain("SameSite"), (header) -> assertThat(header).contains("relaxed=test").contains("SameSite=Lax"), (header) -> assertThat(header).contains("empty=test").contains("SameSite=None"), (header) -> assertThat(header).contains("controlled=test").contains("SameSite=Strict"));
}
use of cn.taketoday.http.client.ClientHttpResponse in project today-framework by TAKETODAY.
the class AbstractServletWebServerFactoryTests method serverHeaderIsDisabledByDefault.
@Test
void serverHeaderIsDisabledByDefault() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
this.webServer = factory.getWebServer(exampleServletRegistration());
this.webServer.start();
ClientHttpResponse response = getClientResponse(getLocalUrl("/hello"));
assertThat(response.getHeaders().getFirst("server")).isNull();
}
use of cn.taketoday.http.client.ClientHttpResponse in project today-framework by TAKETODAY.
the class AbstractServletWebServerFactoryTests method sessionCookieSameSiteAttributeCanBeConfiguredAndOnlyAffectsSessionCookiesWhenUsingCustomName.
@ParameterizedTest
@EnumSource(SameSite.class)
void sessionCookieSameSiteAttributeCanBeConfiguredAndOnlyAffectsSessionCookiesWhenUsingCustomName(SameSite sameSite) throws Exception {
AbstractServletWebServerFactory factory = getFactory();
factory.getSession().getCookie().setName("THESESSION");
factory.getSession().getCookie().setSameSite(sameSite);
factory.addInitializers(new ServletRegistrationBean<>(new CookieServlet(false), "/"));
this.webServer = factory.getWebServer();
this.webServer.start();
ClientHttpResponse clientResponse = getClientResponse(getLocalUrl("/"));
List<String> setCookieHeaders = clientResponse.getHeaders().get("Set-Cookie");
assertThat(setCookieHeaders).satisfiesExactlyInAnyOrder((header) -> assertThat(header).contains("THESESSION").contains("SameSite=" + sameSite.attributeValue()), (header) -> assertThat(header).contains("test=test").doesNotContain("SameSite"));
}
Aggregations