deno.land / std@0.224.0 / http / negotiation_test.ts

negotiation_test.ts
View Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "../assert/mod.ts";import { accepts, acceptsEncodings, acceptsLanguages } from "./negotiation.ts";
Deno.test({ name: "accepts() handles no args", fn() { const req = new Request("https://example.com/", { headers: { "accept": "text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8", }, }); assertEquals(accepts(req), [ "text/html", "application/xhtml+xml", "image/webp", "application/xml", "*/*", ]); },});
Deno.test({ name: "accepts() handles args", fn() { const req = new Request("https://example.com/", { headers: { "accept": "text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8", }, }); assertEquals(accepts(req, "text/html", "image/webp"), "text/html"); },});
Deno.test({ name: "accepts() handles no match", fn() { const req = new Request("https://example.com/", { headers: { "accept": "text/html, application/xhtml+xml, application/xml", }, }); assertEquals(accepts(req, "application/json"), undefined); },});
Deno.test({ name: "accepts() handles args and no header", fn() { const req = new Request("https://example.com/"); assertEquals(accepts(req, "text/html", "image/webp"), "text/html"); },});
Deno.test({ name: "accepts() handles no args and no header", fn() { const req = new Request("https://example.com/"); assertEquals(accepts(req), ["*/*"]); },});
Deno.test({ name: "acceptsEncodings() handles no args", fn() { const req = new Request("https://example.com/", { headers: { "accept-encoding": "deflate, gzip;q=1.0, *;q=0.5" }, }); assertEquals(acceptsEncodings(req), ["deflate", "gzip", "*"]); },});
Deno.test({ name: "acceptsEncodings() handles args", fn() { const req = new Request("https://example.com/", { headers: { "accept-encoding": "deflate, gzip;q=1.0, *;q=0.5" }, }); assertEquals(acceptsEncodings(req, "gzip", "identity"), "gzip"); },});
Deno.test({ name: "acceptsEncodings() handles no match", fn() { const req = new Request("https://example.com/", { headers: { "accept-encoding": "deflate, gzip" }, }); assertEquals(acceptsEncodings(req, "brotli"), undefined); },});
Deno.test({ name: "acceptsEncodings() handles args and no header", fn() { const req = new Request("https://example.com/"); assertEquals(acceptsEncodings(req, "gzip", "identity"), "gzip"); },});
Deno.test({ name: "acceptsEncodings() handles no args and no header", fn() { const req = new Request("https://example.com/"); assertEquals(acceptsEncodings(req), ["*"]); },});
Deno.test({ name: "acceptsLanguages() handles no args", fn() { const req = new Request("https://example.com/", { headers: { "accept-language": "fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5", }, }); assertEquals(acceptsLanguages(req), ["fr-CH", "fr", "en", "de", "*"]); },});
Deno.test({ name: "acceptsLanguages() handles args", fn() { const req = new Request("https://example.com/", { headers: { "accept-language": "fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5", }, }); assertEquals(acceptsLanguages(req, "en-gb", "en-us", "en"), "en"); },});
Deno.test({ name: "acceptsLanguages() handles no match", fn() { const req = new Request("https://example.com/", { headers: { "accept-language": "fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7" }, }); assertEquals(acceptsLanguages(req, "zh"), undefined); },});
Deno.test({ name: "acceptsLanguages() handles args and no header", fn() { const req = new Request("https://example.com/"); assertEquals(acceptsLanguages(req, "en-gb", "en-us", "en"), "en-gb"); },});
Deno.test({ name: "acceptsLanguages() handles no args and no header", fn() { const req = new Request("https://example.com/"); assertEquals(acceptsLanguages(req), ["*"]); },});
std

Version Info

Tagged at
6 months ago