use of org.springframework.http.client.ClientHttpResponse in project spring-boot by spring-projects.
the class AbstractServletWebServerFactoryTests method sessionCookieSameSiteAttributeCanBeConfiguredAndOnlyAffectsSessionCookies.
@ParameterizedTest
@EnumSource(SameSite.class)
void sessionCookieSameSiteAttributeCanBeConfiguredAndOnlyAffectsSessionCookies(SameSite sameSite) throws Exception {
AbstractServletWebServerFactory factory = getFactory();
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("JSESSIONID").contains("SameSite=" + sameSite.attributeValue()), (header) -> assertThat(header).contains("test=test").doesNotContain("SameSite"));
}
use of org.springframework.http.client.ClientHttpResponse in project spring-boot by spring-projects.
the class AbstractServletWebServerFactoryTests method cannotReadClassPathFiles.
@Test
void cannotReadClassPathFiles() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
this.webServer = factory.getWebServer(exampleServletRegistration());
this.webServer.start();
ClientHttpResponse response = getClientResponse(getLocalUrl("/org/springframework/boot/SpringApplication.class"));
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
use of org.springframework.http.client.ClientHttpResponse in project spring-boot by spring-projects.
the class AbstractServletWebServerFactoryTests method serverHeaderIsDisabledByDefaultWhenUsingSsl.
@Test
void serverHeaderIsDisabledByDefaultWhenUsingSsl() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
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).build();
ClientHttpResponse response = getClientResponse(getLocalUrl("https", "/hello"), HttpMethod.GET, new HttpComponentsClientHttpRequestFactory(httpClient));
assertThat(response.getHeaders().get("Server")).isNullOrEmpty();
}
use of org.springframework.http.client.ClientHttpResponse in project spring-boot by spring-projects.
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 org.springframework.http.client.ClientHttpResponse in project spring-boot by spring-projects.
the class RestTemplateExchangeTagsTests method outcomeTagIsInformationalWhenResponseIs1xx.
@Test
void outcomeTagIsInformationalWhenResponseIs1xx() {
ClientHttpResponse response = new MockClientHttpResponse("foo".getBytes(), HttpStatus.CONTINUE);
Tag tag = RestTemplateExchangeTags.outcome(response);
assertThat(tag.getValue()).isEqualTo("INFORMATIONAL");
}
Aggregations