(warc) Fix NPE in WarcRecorder

This commit is contained in:
Viktor Lofgren 2023-12-25 00:48:42 +01:00
parent 85f906ea53
commit 1755b646b8
2 changed files with 20 additions and 1 deletions

View File

@ -203,7 +203,14 @@ public class WarcRecorder implements AutoCloseable {
WarcDigestBuilder responseDigestBuilder = new WarcDigestBuilder();
WarcDigestBuilder payloadDigestBuilder = new WarcDigestBuilder();
byte[] bytes = documentBody.getBytes();
byte[] bytes;
if (documentBody == null) {
bytes = new byte[0];
}
else {
bytes = documentBody.getBytes();
}
String fakeHeaders = STR."""
Content-Type: \{contentType}

View File

@ -91,6 +91,18 @@ class WarcRecorderTest {
}
}
@Test
public void flagAsSkippedNullBody() throws IOException, URISyntaxException {
try (var recorder = new WarcRecorder(fileNameWarc)) {
recorder.flagAsSkipped(new EdgeUrl("https://www.marginalia.nu/"),
"text/html",
200,
null);
}
}
@Test
public void testSaveImport() throws URISyntaxException, IOException {
try (var recorder = new WarcRecorder(fileNameWarc)) {