Search in sources :

Example 16 with HttpHeader

use of com.github.mjeanroy.junit.servers.client.HttpHeader in project junit-servers by mjeanroy.

the class AbstractHttpResponse method getCookie.

@Override
public Cookie getCookie(String name) {
    notBlank(name, "name");
    HttpHeader header = getHeader(SET_COOKIE);
    if (header == null) {
        return null;
    }
    // Check each cookie to find cookie by its name
    for (String value : header.getValues()) {
        Cookie cookie = read(value);
        if (cookie.getName().equals(name)) {
            return cookie;
        }
    }
    // No matching
    return null;
}
Also used : Cookie(com.github.mjeanroy.junit.servers.client.Cookie) HttpHeader(com.github.mjeanroy.junit.servers.client.HttpHeader)

Example 17 with HttpHeader

use of com.github.mjeanroy.junit.servers.client.HttpHeader in project junit-servers by mjeanroy.

the class AbstractHttpResponse method getCookies.

@Override
public List<Cookie> getCookies() {
    HttpHeader header = getHeader(SET_COOKIE);
    if (header == null) {
        return emptyList();
    }
    List<String> values = header.getValues();
    List<Cookie> cookies = new ArrayList<>(values.size());
    for (String value : values) {
        cookies.add(read(value));
    }
    return unmodifiableList(cookies);
}
Also used : Cookie(com.github.mjeanroy.junit.servers.client.Cookie) HttpHeader(com.github.mjeanroy.junit.servers.client.HttpHeader) ArrayList(java.util.ArrayList)

Example 18 with HttpHeader

use of com.github.mjeanroy.junit.servers.client.HttpHeader in project junit-servers by mjeanroy.

the class NingAsyncHttpResponse method getHeaders.

@Override
public Collection<HttpHeader> getHeaders() {
    FluentCaseInsensitiveStringsMap headers = response.getHeaders();
    List<HttpHeader> results = new ArrayList<>(headers.size());
    for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
        results.add(HttpHeader.header(entry.getKey(), entry.getValue()));
    }
    return results;
}
Also used : HttpHeader(com.github.mjeanroy.junit.servers.client.HttpHeader) FluentCaseInsensitiveStringsMap(com.ning.http.client.FluentCaseInsensitiveStringsMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) FluentCaseInsensitiveStringsMap(com.ning.http.client.FluentCaseInsensitiveStringsMap) Map(java.util.Map)

Example 19 with HttpHeader

use of com.github.mjeanroy.junit.servers.client.HttpHeader in project junit-servers by mjeanroy.

the class ApacheHttpResponse method getHeaders.

@Override
public Collection<HttpHeader> getHeaders() {
    final Header[] headers = response.getAllHeaders();
    if (headers == null || headers.length == 0) {
        return emptyList();
    }
    final Map<String, HttpHeader.Builder> builders = new HashMap<>();
    for (Header h : headers) {
        final String name = h.getName();
        final String value = h.getValue();
        final String key = h.getName().toLowerCase();
        HttpHeader.Builder current = builders.get(key);
        if (current == null) {
            current = HttpHeader.builder(name);
            builders.put(key, current);
        }
        current.addValue(value);
    }
    final List<HttpHeader> results = new ArrayList<>(builders.size());
    for (HttpHeader.Builder header : builders.values()) {
        results.add(header.build());
    }
    return unmodifiableList(results);
}
Also used : HttpHeader(com.github.mjeanroy.junit.servers.client.HttpHeader) Header(org.apache.http.Header) HttpHeader(com.github.mjeanroy.junit.servers.client.HttpHeader) HashMap(java.util.HashMap) ToStringBuilder(com.github.mjeanroy.junit.servers.commons.lang.ToStringBuilder) ArrayList(java.util.ArrayList)

Example 20 with HttpHeader

use of com.github.mjeanroy.junit.servers.client.HttpHeader in project junit-servers by mjeanroy.

the class ApacheHttpResponse method getHeader.

@Override
public HttpHeader getHeader(String name) {
    Header[] values = response.getHeaders(name);
    if (values == null || values.length == 0) {
        return null;
    }
    HttpHeader.Builder builder = HttpHeader.builder(name);
    for (Header header : values) {
        builder.addValue(header.getValue());
    }
    return builder.build();
}
Also used : HttpHeader(com.github.mjeanroy.junit.servers.client.HttpHeader) Header(org.apache.http.Header) HttpHeader(com.github.mjeanroy.junit.servers.client.HttpHeader)

Aggregations

HttpHeader (com.github.mjeanroy.junit.servers.client.HttpHeader)31 Test (org.junit.jupiter.api.Test)21 ArrayList (java.util.ArrayList)4 Cookie (com.github.mjeanroy.junit.servers.client.Cookie)3 HttpResponse (com.github.mjeanroy.junit.servers.client.HttpResponse)2 Pair (com.github.mjeanroy.junit.servers.utils.commons.Pair)2 WireMockTest (com.github.mjeanroy.junit.servers.utils.jupiter.WireMockTest)2 Map (java.util.Map)2 Header (org.apache.http.Header)2 HttpClientConfiguration (com.github.mjeanroy.junit.servers.client.HttpClientConfiguration)1 HttpRequest (com.github.mjeanroy.junit.servers.client.HttpRequest)1 HttpRequestBodies.multipartBuilder (com.github.mjeanroy.junit.servers.client.HttpRequestBodies.multipartBuilder)1 HttpUrl (com.github.mjeanroy.junit.servers.client.HttpUrl)1 ToStringBuilder (com.github.mjeanroy.junit.servers.commons.lang.ToStringBuilder)1 EmbeddedServerMockBuilder (com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder)1 FluentCaseInsensitiveStringsMap (com.ning.http.client.FluentCaseInsensitiveStringsMap)1 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)1 HashMap (java.util.HashMap)1 List (java.util.List)1