Skip to content

Commit

Permalink
add If-Match support
Browse files Browse the repository at this point in the history
  • Loading branch information
LiviaMedeiros committed Sep 4, 2023
1 parent 8599feb commit 36ee82f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/http.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const httpOpts = new Map([
[403, { status: 403, statusText: 'Forbidden' }],
[404, { status: 404, statusText: 'Not Found' }],
[405, { status: 405, statusText: 'Method Not Allowed', headers: HEADERS_ALLOW }],
[412, { status: 412, statusText: 'Precondition Failed' }],
[416, { status: 416, statusText: 'Range Not Satisfiable' }],
[422, { status: 422, statusText: 'Unprocessable Content' }],
[500, { status: 500, statusText: 'Internal Server Error' }],
Expand Down
11 changes: 11 additions & 0 deletions lib/methods.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ const GET = async (url, { headers, integrity, signal }) => {
await statsAsOptions(stats, { status: 304 })
);

if (headers.has('If-Match') &&
!headers.get('If-Match')
.split(',')
.map($ => $.trim())
.includes(computeWeakETag(stats))
)
return new Response(
null,
await statsAsOptions(stats, { status: 412 })
);

const ranges = getRanges(headers);

return ranges.length
Expand Down

0 comments on commit 36ee82f

Please sign in to comment.