From d250e2a47b6f6660bc1903e73e44e973360e542e Mon Sep 17 00:00:00 2001 From: Jason Eric Klaes Hoetger Date: Sun, 13 Mar 2016 11:20:00 -0700 Subject: [PATCH] Fixing missing response.content.mimeType in HAR when the server does not send a ContentType header --- .../java/net/lightbody/bmp/filters/HarCaptureFilter.java | 5 ++++- .../src/main/java/net/lightbody/bmp/core/har/HarContent.java | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/browsermob-core-littleproxy/src/main/java/net/lightbody/bmp/filters/HarCaptureFilter.java b/browsermob-core-littleproxy/src/main/java/net/lightbody/bmp/filters/HarCaptureFilter.java index 5f01694b3..a6a3f0229 100644 --- a/browsermob-core-littleproxy/src/main/java/net/lightbody/bmp/filters/HarCaptureFilter.java +++ b/browsermob-core-littleproxy/src/main/java/net/lightbody/bmp/filters/HarCaptureFilter.java @@ -523,7 +523,10 @@ protected void captureResponse(HttpResponse httpResponse) { protected void captureResponseMimeType(HttpResponse httpResponse) { String contentType = HttpHeaders.getHeader(httpResponse, HttpHeaders.Names.CONTENT_TYPE); - harEntry.getResponse().getContent().setMimeType(contentType); + // don't set the mimeType to null, since mimeType is a required field + if (contentType != null) { + harEntry.getResponse().getContent().setMimeType(contentType); + } } protected void captureResponseCookies(HttpResponse httpResponse) { diff --git a/browsermob-core/src/main/java/net/lightbody/bmp/core/har/HarContent.java b/browsermob-core/src/main/java/net/lightbody/bmp/core/har/HarContent.java index 8bfa7db0b..48b67583e 100644 --- a/browsermob-core/src/main/java/net/lightbody/bmp/core/har/HarContent.java +++ b/browsermob-core/src/main/java/net/lightbody/bmp/core/har/HarContent.java @@ -6,7 +6,11 @@ public class HarContent { private volatile long size; private volatile Long compression; + + // mimeType is required; though it shouldn't be set to null, if it is, it still needs to be included to comply with the HAR spec + @JsonInclude(JsonInclude.Include.ALWAYS) private volatile String mimeType = ""; + private volatile String text; private volatile String encoding; private volatile String comment = "";