use of org.springframework.http.HttpHeaders in project spring-framework by spring-projects.
the class RequestMappingMessageConversionIntegrationTests method resource.
@Test
public void resource() throws Exception {
ResponseEntity<byte[]> response = performGet("/resource", new HttpHeaders(), byte[].class);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertTrue(response.hasBody());
assertEquals(951, response.getHeaders().getContentLength());
assertEquals(951, response.getBody().length);
assertEquals(new MediaType("image", "x-png"), response.getHeaders().getContentType());
}
use of org.springframework.http.HttpHeaders in project spring-framework by spring-projects.
the class MockMultipartHttpServletRequest method getMultipartHeaders.
@Override
public HttpHeaders getMultipartHeaders(String paramOrFileName) {
String contentType = getMultipartContentType(paramOrFileName);
if (contentType != null) {
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", contentType);
return headers;
} else {
return null;
}
}
use of org.springframework.http.HttpHeaders in project spring-framework by spring-projects.
the class MockMvcClientHttpRequestFactory method createRequest.
@Override
public ClientHttpRequest createRequest(final URI uri, final HttpMethod httpMethod) throws IOException {
return new MockClientHttpRequest(httpMethod, uri) {
@Override
public ClientHttpResponse executeInternal() throws IOException {
try {
MockHttpServletRequestBuilder requestBuilder = request(httpMethod, uri);
requestBuilder.content(getBodyAsBytes());
requestBuilder.headers(getHeaders());
MvcResult mvcResult = MockMvcClientHttpRequestFactory.this.mockMvc.perform(requestBuilder).andReturn();
MockHttpServletResponse servletResponse = mvcResult.getResponse();
HttpStatus status = HttpStatus.valueOf(servletResponse.getStatus());
byte[] body = servletResponse.getContentAsByteArray();
HttpHeaders headers = getResponseHeaders(servletResponse);
MockClientHttpResponse clientResponse = new MockClientHttpResponse(body, status);
clientResponse.getHeaders().putAll(headers);
return clientResponse;
} catch (Exception ex) {
byte[] body = ex.toString().getBytes(StandardCharsets.UTF_8);
return new MockClientHttpResponse(body, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
};
}
use of org.springframework.http.HttpHeaders in project spring-framework by spring-projects.
the class HeaderAssertionsTests method valueMatches.
@Test
public void valueMatches() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
HeaderAssertions assertions = headerAssertions(headers);
// Success
assertions.valueMatches("Content-Type", ".*UTF-8.*");
try {
assertions.valueMatches("Content-Type", ".*ISO-8859-1.*");
fail("Wrong pattern expected");
} catch (AssertionError error) {
Throwable cause = error.getCause();
assertNotNull(cause);
assertEquals("Response header [Content-Type]='application/json;charset=UTF-8' " + "does not match '.*ISO-8859-1.*'", cause.getMessage());
}
}
use of org.springframework.http.HttpHeaders in project spring-framework by spring-projects.
the class ReactorClientHttpResponse method getHeaders.
@Override
public HttpHeaders getHeaders() {
HttpHeaders headers = new HttpHeaders();
this.response.responseHeaders().entries().forEach(e -> headers.add(e.getKey(), e.getValue()));
return headers;
}
Aggregations