udacity / cloudflare-typescript-workers

Types and mocks for building a tested Typescript Cloudflare Worker, generates three NPM packages
Apache License 2.0
139 stars 12 forks source link

Chore: Add new Request.cf object attributes #7

Closed 13rac1 closed 4 years ago

13rac1 commented 5 years ago

Cloudflare has added additional incoming and outgoing fields to the Request.cf object. This adds new fields listed in https://workers.cloudflare.com/docs/reference/runtime/apis/fetch/

Change: All CloudflareRequestAttributes fields are now optional to ease testing. Avoids forcing the developer to create an object full of unused, but required fields. This requires null checks in the worker code, but they should have arguably been there from the start.

CloudflareRequestAttributes object to avoid

export const testIncomingRequest: CloudflareRequestAttributes = {
  asn: '123456',
  colo: 'ABC',
  country: 'US',
  exclusive: '1',
  group: '100',
  'group-weight': '0',
  tlsCipher: 'AEAD-AES128-GCM-SHA256',
  tlsClientAuth: {
    certFingerprintSHA1: 'abcdef',
    certIssuerDN: 'example',
    certIssuerDNLegacy: 'example',
    certNotAfter: 'Dec 22 19:39:00 2018 GMT',
    certNotBefore: 'Dec 22 19:39:00 2018 GMT',
    certPresented: '1',
    certSerial: '123456',
    certSubjectDN: 'example',
    certSubjectDNLegacy: 'example',
    certVerified: 'SUCCESS',
  },
  tlsVersion: 'TLSv1.3',
  weight: '100',
};