use of org.apache.hc.core5.http.HttpHeaders in project californium by eclipse.
the class CrossProtocolTranslatorTest method testHttpHeader.
@Test
public void testHttpHeader() throws Exception {
OptionSet set = new OptionSet();
set.setUriHost("test");
set.setLocationPath("test/location");
set.setLocationQuery("t1=a&var");
set.setAccept(MediaTypeRegistry.APPLICATION_JSON);
set.addETag(new byte[] { 0x01, 0x02 });
set.setMaxAge(24);
set.setContentFormat(MediaTypeRegistry.APPLICATION_XML);
List<Header> httpHeaders = Arrays.asList(translator.getHttpHeaders(set.asSortedList(), coapEtagTranslator));
assertThat(httpHeaders.size(), is(4));
assertThat(httpHeaders, hasItem(hasHttpHeader("Etag", "0102")));
assertThat(httpHeaders, hasItem(hasHttpHeader("Accept", "application/json; charset=UTF-8")));
assertThat(httpHeaders, hasItem(hasHttpHeader("Cache-Control", "max-age=24")));
assertThat(httpHeaders, hasItem(hasHttpHeader("Content-Location", "/test/location?t1=a&var")));
}
use of org.apache.hc.core5.http.HttpHeaders in project spring-framework by spring-projects.
the class HttpComponentsClientHttpRequest method applyHeaders.
@Override
protected void applyHeaders() {
HttpHeaders headers = getHeaders();
headers.entrySet().stream().filter(entry -> !HttpHeaders.CONTENT_LENGTH.equals(entry.getKey())).forEach(entry -> entry.getValue().forEach(v -> this.httpRequest.addHeader(entry.getKey(), v)));
if (!this.httpRequest.containsHeader(HttpHeaders.ACCEPT)) {
this.httpRequest.addHeader(HttpHeaders.ACCEPT, MediaType.ALL_VALUE);
}
this.contentLength = headers.getContentLength();
}
Aggregations