use of edu.umass.cs.benchlab.har.HarEntry in project zaproxy by zaproxy.
the class SearchAPI method handleApiOther.
@Override
public HttpMessage handleApiOther(HttpMessage msg, String name, JSONObject params) throws ApiException {
byte[] responseBody = {};
ExtensionSearch.Type searchType;
switch(name) {
case OTHER_HAR_BY_URL_REGEX:
searchType = ExtensionSearch.Type.URL;
break;
case OTHER_HAR_BY_REQUEST_REGEX:
searchType = ExtensionSearch.Type.Request;
break;
case OTHER_HAR_BY_RESPONSE_REGEX:
searchType = ExtensionSearch.Type.Response;
break;
case OTHER_HAR_BY_HEADER_REGEX:
searchType = ExtensionSearch.Type.Header;
break;
default:
throw new ApiException(ApiException.Type.BAD_OTHER);
}
validateRegex(params);
try {
final HarEntries entries = new HarEntries();
search(params, searchType, rh -> {
HarEntry entry = HarUtils.createHarEntry(rh.getHistoryId(), rh.getHistoryType(), rh.getHttpMessage());
entries.addEntry(entry);
});
HarLog harLog = HarUtils.createZapHarLog();
harLog.setEntries(entries);
responseBody = HarUtils.harLogToByteArray(harLog);
} catch (Exception e) {
log.error(e.getMessage(), e);
ApiException apiException = new ApiException(ApiException.Type.INTERNAL_ERROR, e.getMessage());
responseBody = apiException.toString(API.Format.JSON, incErrorDetails()).getBytes(StandardCharsets.UTF_8);
}
try {
msg.setResponseHeader(API.getDefaultResponseHeader("application/json; charset=UTF-8", responseBody.length));
} catch (HttpMalformedHeaderException e) {
log.error("Failed to create response header: " + e.getMessage(), e);
}
msg.setResponseBody(responseBody);
return msg;
}
use of edu.umass.cs.benchlab.har.HarEntry in project zaproxy by zaproxy.
the class HarUtils method createHarEntry.
/**
* Creates a {@code HarEntry} from the given message with additional custom fields for the
* history ID/type and note.
*
* @param historyId the history ID of the HTTP message.
* @param historyType the history type of the HTTP message.
* @param httpMessage the HTTP message.
* @return the {@code HarEntry}, never {@code null}.
* @since 2.8.0
* @see #createMessageHarCustomFields(int, int, String)
*/
public static HarEntry createHarEntry(int historyId, int historyType, HttpMessage httpMessage) {
HarEntry entry = createHarEntry(httpMessage);
entry.setCustomFields(createMessageHarCustomFields(historyId, historyType, httpMessage.getNote()));
return entry;
}
Aggregations