use of cn.taketoday.http.client.ClientHttpResponse in project today-infrastructure 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"));
}
use of cn.taketoday.http.client.ClientHttpResponse in project today-infrastructure by TAKETODAY.
the class AbstractServletWebServerFactoryTests method customServerHeader.
@Test
void customServerHeader() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
factory.setServerHeader("MyServer");
this.webServer = factory.getWebServer(exampleServletRegistration());
this.webServer.start();
ClientHttpResponse response = getClientResponse(getLocalUrl("/hello"));
assertThat(response.getHeaders().getFirst("server")).isEqualTo("MyServer");
}
use of cn.taketoday.http.client.ClientHttpResponse in project today-infrastructure 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-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();
}
use of cn.taketoday.http.client.ClientHttpResponse in project today-infrastructure by TAKETODAY.
the class ServletWebServerMvcIntegrationTests method doTest.
private void doTest(AnnotationConfigServletWebServerApplicationContext context, String resourcePath) throws Exception {
SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
ClientHttpRequest request = clientHttpRequestFactory.createRequest(new URI("http://localhost:" + context.getWebServer().getPort() + resourcePath), HttpMethod.GET);
try (ClientHttpResponse response = request.execute()) {
assertThat(response.getBody()).hasContent("Hello World");
}
}
Aggregations