Skip to content

Commit

Permalink
use 'application/octet-stream' as default Content-Type for resource (…
Browse files Browse the repository at this point in the history
…and other records) if no warc content-type is specified

addresses issue discussed in #22
  • Loading branch information
ikreymer committed Apr 9, 2021
1 parent 34b8383 commit e948c1b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "warcio",
"version": "1.4.2",
"version": "1.4.3",
"main": "index.js",
"module": "main.js",
"license": "Apache-2.0",
Expand Down
4 changes: 2 additions & 2 deletions src/warcrecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class WARCRecord extends BaseAsyncIterReader
warcHeaders.headers.set("WARC-Record-ID", `<urn:uuid:${uuid()}>`);
}

if (!warcHeaders.headers.get("Content-Type") && defaultRecordCT[type]) {
warcHeaders.headers.set("Content-Type", defaultRecordCT[type]);
if (!warcHeaders.headers.get("Content-Type")) {
warcHeaders.headers.set("Content-Type", defaultRecordCT[type] || "application/octet-stream");
}

if (!reader) {
Expand Down
20 changes: 20 additions & 0 deletions test/testSerializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,26 @@ test('test auto record id, current date', async t => {

});

test('test default content-type for resource', async t => {
async function* payload() {
yield encoder.encode('some text');
}

const url = "urn:custom:http://example.com/";
const type = "resource";
const warcHeaders = {};

const record = await WARCRecord.create({url, type, warcHeaders}, payload());

t.is(record.warcContentType, "application/octet-stream");
t.not(record.warcDate, null);
t.not(record.warcHeader("WARC-Record-ID", null));
t.not(record.warcPayloadDigest, null);
t.is(record.warcPayloadDigest, record.warcBlockDigest);

});



const createRecordGzipped = async (t) => {

Expand Down

0 comments on commit e948c1b

Please sign in to comment.