UNPKG

3.61 kBTypeScriptView Raw
1/// <reference lib="webworker" />
2
3declare global {
4 interface Request {
5 cf: IncomingCloudflareProperties;
6 }
7}
8
9export type Params = Record<string, string>;
10
11/** @see {require('http').METHODS} */
12export type Method = 'ACL' | 'BIND' | 'CHECKOUT' | 'CONNECT' | 'COPY' | 'DELETE' | 'GET' | 'HEAD' | 'LINK' | 'LOCK' | 'M-SEARCH' | 'MERGE' | 'MKACTIVITY' | 'MKCALENDAR' | 'MKCOL' | 'MOVE' | 'NOTIFY' | 'OPTIONS' | 'PATCH' | 'POST' | 'PRI' | 'PROPFIND' | 'PROPPATCH' | 'PURGE' | 'PUT' | 'REBIND' | 'REPORT' | 'SEARCH' | 'SOURCE' | 'SUBSCRIBE' | 'TRACE' | 'UNBIND' | 'UNLINK' | 'UNLOCK' | 'UNSUBSCRIBE';
13
14/** @see https://developers.cloudflare.com/workers/runtime-apis/request#incomingrequestcfproperties */
15export interface IncomingCloudflareProperties {
16 /**
17 * The ASN of the incoming request
18 * @example "395747"
19 **/
20 asn: string;
21 /**
22 * The three-letter `IATA` airport code of the data center that the request hit
23 * @example "DFW"
24 */
25 colo: string;
26 /**
27 * The two-letter country code in the request.
28 * @note This is the same value as that provided in the `CF-IPCountry` header
29 * @example "US"
30 */
31 country: string | null;
32 /**
33 * The HTTP Protocol
34 * @example "HTTP/2"
35 */
36 httpProtocol: string;
37 /**
38 * The browser-requested prioritization information in the request object
39 * @example "weight=192;exclusive=0;group=3;group-weight=127"
40 */
41 requestPriority?: string;
42 /**
43 * The cipher for the connection to Cloudflare
44 * @example "AEAD-AES128-GCM-SHA256"
45 */
46 tlsCipher: string;
47 /**
48 * @note Requires Cloudflare Access or API Shield
49 */
50 tlsClientAuth?: {
51 certIssuerDN: string;
52 certIssuerDNLegacy: string;
53 certPresented: '0' | '1';
54 certSubjectDNLegacy: string;
55 certSubjectDN: string;
56 /** @example "Dec 22 19:39:00 2018 GMT" */
57 certNotBefore: string;
58 /** @example "Dec 22 19:39:00 2018 GMT" */
59 certNotAfter: string;
60 certFingerprintSHA1: string;
61 certSerial: string;
62 /** @example "SUCCESS", "FAILED:reason", "NONE" */
63 certVerified: string;
64 };
65 /**
66 * The TLS version of the connection to Cloudflare
67 * @example "TLSv1.3"
68 */
69 tlsVersion: string;
70 /**
71 * City of the incoming request
72 * @example "Austin"
73 **/
74 city?: string;
75 /**
76 * Continent of the incoming request
77 * @example "NA"
78 **/
79 continent?: string;
80 /**
81 * Latitude of the incoming request
82 * @example "30.27130"
83 **/
84 latitude?: string;
85 /**
86 * Longitude of the incoming request
87 * @example "-97.74260"
88 **/
89 longitude?: string;
90 /**
91 * Postal code of the incoming request
92 * @example "78701"
93 **/
94 postalCode?: string;
95 /**
96 * Metro code (DMA) of the incoming request
97 * @example "635"
98 **/
99 metroCode?: string;
100 /**
101 * If known, the `ISO 3166-2` name for the first level region associated with the IP address of the incoming request
102 * @example "Texas"
103 **/
104 region?: string;
105 /**
106 * If known, the `ISO 3166-2` code for the first level region associated with the IP address of the incoming request
107 * @example "TX"
108 **/
109 regionCode?: string;
110 /**
111 * Timezone of the incoming request
112 * @example "America/Chicago".
113 **/
114 timezone: string;
115}
116
117export declare class ServerRequest<P extends Params = Params> {
118 constructor(event: FetchEvent);
119 url: string;
120 path: string;
121 method: Method;
122 origin: string;
123 hostname: string;
124 search: string;
125 query: URLSearchParams;
126 extend: FetchEvent['waitUntil'];
127 cf: IncomingCloudflareProperties;
128 headers: Headers;
129 params: P;
130 body: {
131 <T>(): Promise<T|void>;
132 json<T=any>(): Promise<T>;
133 arrayBuffer(): Promise<ArrayBuffer>;
134 formData(): Promise<FormData>;
135 text(): Promise<string>;
136 blob(): Promise<Blob>;
137 };
138}