use of edu.umass.cs.benchlab.har.HarContent in project zaproxy by zaproxy.
the class HarUtils method createHarResponse.
public static HarResponse createHarResponse(HttpMessage httpMessage) {
HttpResponseHeader responseHeader = httpMessage.getResponseHeader();
HarCookies harCookies = new HarCookies();
long whenCreated = System.currentTimeMillis();
for (HttpCookie cookie : responseHeader.getHttpCookies(httpMessage.getRequestHeader().getHostName())) {
Date expires;
if (cookie.getVersion() == 0) {
expires = new Date(whenCreated + (cookie.getMaxAge() * 1000));
} else {
expires = new Date(httpMessage.getTimeSentMillis() + httpMessage.getTimeElapsedMillis() + (cookie.getMaxAge() * 1000));
}
harCookies.addCookie(new HarCookie(cookie.getName(), cookie.getValue(), cookie.getPath(), cookie.getDomain(), expires, cookie.isHttpOnly(), cookie.getSecure(), null));
}
String text = null;
String encoding = null;
String contentType = responseHeader.getHeader(HttpHeader.CONTENT_TYPE);
if (contentType == null) {
contentType = "";
} else if (!contentType.isEmpty()) {
String lcContentType = contentType.toLowerCase(Locale.ROOT);
final int pos = lcContentType.indexOf(';');
if (pos != -1) {
lcContentType = lcContentType.substring(0, pos).trim();
}
if (!lcContentType.startsWith("text")) {
encoding = "base64";
text = Base64.getEncoder().encodeToString(httpMessage.getResponseBody().getBytes());
} else {
text = httpMessage.getResponseBody().toString();
}
}
HarContent harContent = new HarContent(httpMessage.getResponseBody().length(), 0, contentType, text, encoding, null);
String redirectUrl = responseHeader.getHeader(HttpHeader.LOCATION);
return new HarResponse(responseHeader.getStatusCode(), responseHeader.getReasonPhrase(), responseHeader.getVersion(), harCookies, createHarHeaders(responseHeader), harContent, redirectUrl == null ? "" : redirectUrl, responseHeader.toString().length(), httpMessage.getResponseBody().length(), null);
}
Aggregations