Search in sources :

Example 1 with HttpHeaders

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")));
}
Also used : Header(org.apache.hc.core5.http.Header) BasicHeader(org.apache.hc.core5.http.message.BasicHeader) OptionSet(org.eclipse.californium.core.coap.OptionSet) Test(org.junit.Test)

Example 2 with HttpHeaders

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();
}
Also used : BasicClientCookie(org.apache.hc.client5.http.impl.cookie.BasicClientCookie) BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) CookieStore(org.apache.hc.client5.http.cookie.CookieStore) HttpClientContext(org.apache.hc.client5.http.protocol.HttpClientContext) HttpHeaders(org.springframework.http.HttpHeaders) URISyntaxException(java.net.URISyntaxException) Collection(java.util.Collection) Publisher(org.reactivestreams.Publisher) MediaType(org.springframework.http.MediaType) HttpMethod(org.springframework.http.HttpMethod) Mono(reactor.core.publisher.Mono) DataBuffer(org.springframework.core.io.buffer.DataBuffer) Function(java.util.function.Function) ByteBuffer(java.nio.ByteBuffer) BasicRequestProducer(org.apache.hc.core5.http.nio.support.BasicRequestProducer) Flux(reactor.core.publisher.Flux) ReactiveEntityProducer(org.apache.hc.core5.reactive.ReactiveEntityProducer) HttpRequest(org.apache.hc.core5.http.HttpRequest) DataBufferFactory(org.springframework.core.io.buffer.DataBufferFactory) ContentType(org.apache.hc.core5.http.ContentType) AsyncRequestProducer(org.apache.hc.core5.http.nio.AsyncRequestProducer) Nullable(org.springframework.lang.Nullable) URI(java.net.URI) HttpHeaders(org.springframework.http.HttpHeaders)

Aggregations

URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ByteBuffer (java.nio.ByteBuffer)1 Collection (java.util.Collection)1 Function (java.util.function.Function)1 CookieStore (org.apache.hc.client5.http.cookie.CookieStore)1 BasicClientCookie (org.apache.hc.client5.http.impl.cookie.BasicClientCookie)1 HttpClientContext (org.apache.hc.client5.http.protocol.HttpClientContext)1 ContentType (org.apache.hc.core5.http.ContentType)1 Header (org.apache.hc.core5.http.Header)1 HttpRequest (org.apache.hc.core5.http.HttpRequest)1 BasicHeader (org.apache.hc.core5.http.message.BasicHeader)1 BasicHttpRequest (org.apache.hc.core5.http.message.BasicHttpRequest)1 AsyncRequestProducer (org.apache.hc.core5.http.nio.AsyncRequestProducer)1 BasicRequestProducer (org.apache.hc.core5.http.nio.support.BasicRequestProducer)1 ReactiveEntityProducer (org.apache.hc.core5.reactive.ReactiveEntityProducer)1 OptionSet (org.eclipse.californium.core.coap.OptionSet)1 Test (org.junit.Test)1 Publisher (org.reactivestreams.Publisher)1 DataBuffer (org.springframework.core.io.buffer.DataBuffer)1