Skip to content

Commit b66a82c

Browse files
authored
fix: accept Graphsync measurements without HEAD status (#498)
Fix the regression introduced by e2a458b (#475) Signed-off-by: Miroslav Bajtoš <[email protected]>
1 parent 3c365dd commit b66a82c

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

lib/preprocess.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,14 @@ export const assertValidMeasurement = measurement => {
268268
assert(measurement.end_at >= measurement.first_byte_at, 'end_at must be greater than or equal to first_byte_at')
269269
assert(measurement.first_byte_at >= measurement.start_at, 'first_byte_at must be greater than or equal to start_at')
270270

271-
assert.strictEqual(typeof measurement.head_status_code, 'number', '`head_status_code` must be a number')
271+
if (measurement.protocol === 'http') {
272+
assert.strictEqual(typeof measurement.head_status_code, 'number', '`head_status_code` must be a number')
273+
} else {
274+
assert(
275+
measurement.head_status_code === undefined || measurement.head_status_code === null,
276+
'`head_status_code` must be undefined or null for non-HTTP retrievals'
277+
)
278+
}
272279
}
273280
}
274281

test/preprocess.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,19 +314,48 @@ describe('assertValidMeasurement', () => {
314314
assert.throws(
315315
() => assertValidMeasurement({
316316
...VALID_MEASUREMENT,
317+
protocol: 'http',
317318
head_status_code: null
318319
}),
319320
/`head_status_code` must be a number/
320321
)
321322
assert.throws(
322323
() => assertValidMeasurement({
323324
...VALID_MEASUREMENT,
325+
protocol: 'http',
324326
head_status_code: /** @type {any} */ ('200')
325327
}),
326328
/`head_status_code` must be a number/
327329
)
328330
})
329331

332+
it('accepts Graphsync measurements with OK retrieval result and head_status_code is null', () => {
333+
assertValidMeasurement({
334+
...VALID_MEASUREMENT,
335+
protocol: 'graphsync',
336+
head_status_code: null
337+
338+
})
339+
})
340+
341+
it('accepts Graphsync measurements with OK retrieval result and head_status_code is undefined', () => {
342+
assertValidMeasurement({
343+
...VALID_MEASUREMENT,
344+
protocol: 'graphsync',
345+
head_status_code: undefined
346+
})
347+
})
348+
349+
it('rejects Graphsync measurements with head_status_code not null/undefined ', () => {
350+
assert.throws(
351+
() => assertValidMeasurement({
352+
...VALID_MEASUREMENT,
353+
head_status_code: /** @type {any} */ ('200')
354+
}),
355+
/`head_status_code` must be undefined/
356+
)
357+
})
358+
330359
it('should throw an error for invalid start_at', () => {
331360
const measurement = {
332361
...VALID_MEASUREMENT,

0 commit comments

Comments
 (0)