com.ui4j.api.interceptor.Response Maven / Gradle / Ivy
The newest version!
package com.ui4j.api.interceptor;
import java.net.HttpCookie;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class Response {
private String url;
private Map> headers;
public Response(String url, Map> headers) {
this.url = url;
this.headers = headers;
}
public Map> getHeaders() {
return headers;
}
public HttpCookie getCookie(String name) {
for (HttpCookie cookie : getCookies()) {
if (cookie.getName().equals(name)) {
return cookie;
}
}
return null;
}
public List getCookies() {
List cookies = new ArrayList<>();
if (headers != null) {
List list = headers.get("Set-Cookie");
if (list != null) {
for (String next : list) {
List hc = HttpCookie.parse(next);
if (!hc.isEmpty()) {
cookies.add(hc.get(0));
}
}
}
}
return Collections.unmodifiableList(cookies);
}
public String getHeader(String name) {
List values = headers.get(name);
if (values != null && !values.isEmpty()) {
return values.get(0);
}
return null;
}
public String getUrl() {
return url;
}
@Override
public String toString() {
return "Response [url=" + url + ", headers=" + headers + "]";
}
}