Skip to content

Commit a6bae07

Browse files
committed
docs: update code example
1 parent 0c1da11 commit a6bae07

File tree

7 files changed

+24
-18
lines changed

7 files changed

+24
-18
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ If you implement a `Precondition` that is not in the specification, make sure
194194
`If-Match` header field precondition.
195195

196196
```ts
197-
import { IfMatch } from "https://deno.land/x/conditional_request_middleware@$VERSION/mod.ts";
197+
import { IfMatch } from "https://deno.land/x/conditional_request_middleware@$VERSION/preconditions/if_match.ts";
198198
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
199199

200200
const precondition = new IfMatch();
@@ -234,7 +234,7 @@ If evaluation is `false`:
234234
`If-None-Match` header field precondition.
235235

236236
```ts
237-
import { IfNoneMatch } from "https://deno.land/x/conditional_request_middleware@$VERSION/mod.ts";
237+
import { IfNoneMatch } from "https://deno.land/x/conditional_request_middleware@$VERSION/preconditions/if_none_match.ts";
238238
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
239239

240240
const precondition = new IfNoneMatch();
@@ -275,7 +275,7 @@ If evaluation is `false`:
275275
`If-Modified-Since` header field precondition.
276276

277277
```ts
278-
import { IfModifiedSince } from "https://deno.land/x/conditional_request_middleware@$VERSION/mod.ts";
278+
import { IfModifiedSince } from "https://deno.land/x/conditional_request_middleware@$VERSION/preconditions/if_modified_since.ts";
279279
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
280280

281281
const precondition = new IfModifiedSince();
@@ -318,7 +318,7 @@ If evaluation is `false`:
318318
`If-Unmodified-Since` header field precondition.
319319

320320
```ts
321-
import { IfUnmodifiedSince } from "https://deno.land/x/conditional_request_middleware@$VERSION/mod.ts";
321+
import { IfUnmodifiedSince } from "https://deno.land/x/conditional_request_middleware@$VERSION/preconditions/if_unmodified_since.ts";
322322
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
323323

324324
const precondition = new IfUnmodifiedSince();
@@ -358,7 +358,7 @@ If evaluation is `false`:
358358
`If-Range` header field precondition.
359359

360360
```ts
361-
import { IfRange } from "https://deno.land/x/conditional_request_middleware@$VERSION/mod.ts";
361+
import { IfRange } from "https://deno.land/x/conditional_request_middleware@$VERSION/preconditions/if_range.ts";
362362
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
363363

364364
const precondition = new IfRange();

middleware.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,32 @@ export interface Options {
3434
*
3535
* @example
3636
* ```ts
37-
* import { conditionalRequest } from "https://deno.land/x/conditional_request_middleware@$VERSION/mod.ts";
38-
* import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
37+
* import {
38+
* conditionalRequest,
39+
* type Handler,
40+
* } from "https://deno.land/x/conditional_request_middleware@$VERSION/mod.ts";
41+
* import {
42+
* assertEquals,
43+
* assertFalse,
44+
* } from "https://deno.land/std/testing/asserts.ts";
3945
* import { assertSpyCalls, spy } from "https://deno.land/std/testing/mock.ts";
4046
*
41-
* const selectedRepresentation = new Response("<body>", {
42-
* headers: { etag: "<etag>" },
47+
* const selectRepresentation = spy((request: Request) => {
48+
* return new Response("<body>", { headers: { etag: "<etag>" } });
4349
* });
44-
* const selectRepresentation = spy(() => selectedRepresentation);
4550
* const middleware = conditionalRequest(selectRepresentation);
4651
* const request = new Request("<uri>", {
4752
* headers: { "if-none-match": "<etag>" },
4853
* });
49-
* const handler = spy(() => selectedRepresentation);
54+
* declare const _handler: Handler;
55+
* const handler = spy(_handler);
5056
*
5157
* const response = await middleware(request, handler);
5258
*
5359
* assertSpyCalls(handler, 0);
5460
* assertSpyCalls(selectRepresentation, 1);
5561
* assertEquals(response.status, 304);
62+
* assertFalse(response.body);
5663
* ```
5764
*/
5865
export function conditionalRequest(

preconditions/if_match.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { ifMatch } from "./utils.ts";
1919
*
2020
* @example
2121
* ```ts
22-
* import { IfMatch } from "https://deno.land/x/conditional_request_middleware@$VERSION/mod.ts";
22+
* import { IfMatch } from "https://deno.land/x/conditional_request_middleware@$VERSION/preconditions/if_match.ts";
2323
* import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
2424
*
2525
* const precondition = new IfMatch();

preconditions/if_modified_since.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import type { Precondition } from "../types.ts";
2020
*
2121
* @example
2222
* ```ts
23-
* import { IfModifiedSince } from "https://deno.land/x/conditional_request_middleware@$VERSION/mod.ts";
23+
* import { IfModifiedSince } from "https://deno.land/x/conditional_request_middleware@$VERSION/preconditions/if_modified_since.ts";
2424
* import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
2525
*
2626
* const precondition = new IfModifiedSince();

preconditions/if_none_match.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { isBannedHeader } from "../utils.ts";
2121
*
2222
* @example
2323
* ```ts
24-
* import { IfNoneMatch } from "https://deno.land/x/conditional_request_middleware@$VERSION/mod.ts";
24+
* import { IfNoneMatch } from "https://deno.land/x/conditional_request_middleware@$VERSION/preconditions/if_none_match.ts";
2525
* import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
2626
*
2727
* const precondition = new IfNoneMatch();

preconditions/if_range.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function evaluateIfRange(
5656
*
5757
* @example
5858
* ```ts
59-
* import { IfRange } from "https://deno.land/x/conditional_request_middleware@$VERSION/mod.ts";
59+
* import { IfRange } from "https://deno.land/x/conditional_request_middleware@$VERSION/preconditions/if_range.ts";
6060
* import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
6161
*
6262
* const precondition = new IfRange();

preconditions/if_unmodified_since.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { ifUnmodifiedSince } from "./utils.ts";
1717
*
1818
* @example
1919
* ```ts
20-
* import { IfUnmodifiedSince } from "https://deno.land/x/conditional_request_middleware@$VERSION/mod.ts";
20+
* import { IfUnmodifiedSince } from "https://deno.land/x/conditional_request_middleware@$VERSION/preconditions/if_unmodified_since.ts";
2121
* import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
2222
*
2323
* const precondition = new IfUnmodifiedSince();
@@ -49,8 +49,7 @@ export class IfUnmodifiedSince implements Precondition {
4949
RepresentationHeader.LastModified,
5050
);
5151

52-
// A recipient MUST ignore If-Unmodified-Since if the request contains
53-
// an If-Match header field
52+
// A recipient MUST ignore If-Unmodified-Since if the request contains an If-Match header field
5453
if (
5554
request.headers.has(ConditionalHeader.IfMatch) ||
5655
isNull(fieldValue) ||

0 commit comments

Comments
 (0)