headers v0.10.0
·
29 commits
to main
since this release
This release contains several improvements to Cookie
that bring it more in line with other headers like Accept
, AcceptEncoding
, and AcceptLanguage
.
- BREAKING CHANGE:
cookie.names()
andcookie.values()
are now getters that returnstring[]
instead of methods that returnIterableIterator<string>
- BREAKING CHANGE:
cookie.forEach()
calls its callback with(name, value, cookie)
instead of(value, name, map)
- BREAKING CHANGE:
cookie.delete(name)
returnsvoid
instead ofboolean
// before
let cookieNames = Array.from(headers.cookie.names());
// after
let cookieNames = headers.cookie.names;
Additionally, this release adds support for the If-None-Match
header. This is useful for conditional GET requests where you want to return a response with content only if the ETag has changed.
import { SuperHeaders } from '@mjackson/headers';
function requestHandler(request: Request): Promise<Response> {
let response = await callDownstreamService(request);
if (request.method === 'GET' && response.headers.has('ETag')) {
let headers = new SuperHeaders(request.headers);
if (headers.ifNoneMatch.matches(response.headers.get('ETag'))) {
return new Response(null, { status: 304 });
}
}
return response;
}