Skip to content

headers v0.10.0

Compare
Choose a tag to compare
@github-actions github-actions released this 27 Jan 20:01
· 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() and cookie.values() are now getters that return string[] instead of methods that return IterableIterator<string>
  • BREAKING CHANGE: cookie.forEach() calls its callback with (name, value, cookie) instead of (value, name, map)
  • BREAKING CHANGE: cookie.delete(name) returns void instead of boolean
// 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;
}