Skip to content

Commit

Permalink
Merge pull request #59 from blibli-badak/dev-mh
Browse files Browse the repository at this point in the history
fix har unable to open on chrome inspect
  • Loading branch information
argotri authored Aug 6, 2024
2 parents f3d0df2 + 7aefccc commit 856ad79
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public void setup() {
harEntry.setRequest(convertHarRequest());
if (response != null) {
harEntry.setResponse(convertHarResponse());
} else {
harEntry.setResponse(emptyHarResponse());
}
harEntry.setTimings(convertHarTiming());
harEntry.setPageref(pageRef);
Expand All @@ -68,6 +70,11 @@ public void setup() {
public HarTiming convertHarTiming() {
HarTiming harTiming = new HarTiming();
if (timing == null || timing.isEmpty()) {
harTiming.setDns(-1);
harTiming.setConnect(-1);
harTiming.setSend(-1);
harTiming.setWait(-1);
harTiming.setReceive(-1);
return harTiming;
}
harTiming.setDns(timing.get().getDnsStart().intValue());
Expand All @@ -91,6 +98,17 @@ private HarResponse convertHarResponse() {
return harResponse;
}

private HarResponse emptyHarResponse() {
HarResponse harResponse = new HarResponse();
harResponse.setStatus(0);
harResponse.setStatusText("");
harResponse.setHttpVersion("HTTP/1.1");
harResponse.setRedirectURL("");
harResponse.setHeaders(new ArrayList<>());
harResponse.setContent(setEmptyHarContentResponse());
return harResponse;
}

private String convertInputStreamtoString(InputStream inputStream) {
StringBuilder stringBuilder = new StringBuilder();
try {
Expand All @@ -112,6 +130,13 @@ private HarContent setHarContentResponse() {
return harContent;
}

private HarContent setEmptyHarContentResponse() {
HarContent harContent = new HarContent();
harContent.setSize((long) 0);
harContent.setMimeType("text/plain");
return harContent;
}

private List<HarHeader> convertHarHeadersResponse() {
List<HarHeader> harHeaders = new java.util.ArrayList<>();
response.getHeaders().forEach((key, value) -> {
Expand Down

0 comments on commit 856ad79

Please sign in to comment.