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;
}
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);
}
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;
}
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);
}
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();
}
Aggregations