Skip to content

Commit

Permalink
refactor: move etag to middleware/etag and remove re-exports from std
Browse files Browse the repository at this point in the history
**BREAKING CHANGE** The following APIs were being re-exported from
etag, but have been present in Deno @std/http/etag for an extended
period of time and the re-exports have been removed:

- `calculate`
- `type ETagOptions`
- `type FileInfo`
- `ifMatch`
- `ifNoneMatch`
  • Loading branch information
kitsonk committed Apr 18, 2024
1 parent ba0ecaf commit 70e4cbf
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 37 deletions.
12 changes: 6 additions & 6 deletions etag.test.ts → middleware/etag.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Copyright 2018-2024 the oak authors. All rights reserved. MIT license.

import { assert } from "./deps.ts";
import { assertEquals } from "./test_deps.ts";
import { assert } from "../deps.ts";
import { assertEquals } from "../test_deps.ts";
import {
createMockApp,
createMockContext,
mockContextState,
} from "./testing.ts";
} from "../testing.ts";

import type { Application } from "./application.ts";
import type { Context } from "./context.ts";
import type { RouteParams } from "./router.ts";
import type { Application } from "../application.ts";
import type { Context } from "../context.ts";
import type { RouteParams } from "../router.ts";

import { factory } from "./etag.ts";

Expand Down
21 changes: 6 additions & 15 deletions etag.ts → middleware/etag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,12 @@
* @module
*/

import type { State } from "./application.ts";
import type { Context } from "./context.ts";
import { calculate, type ETagOptions } from "./deps.ts";
import type { Middleware } from "./middleware.ts";
import { BODY_TYPES } from "./utils/consts.ts";
import { isAsyncIterable, isReader } from "./utils/type_guards.ts";

// re-exports to maintain backwards compatibility
export {
calculate,
type ETagOptions,
type FileInfo,
ifMatch,
ifNoneMatch,
} from "./deps.ts";
import type { State } from "../application.ts";
import type { Context } from "../context.ts";
import { calculate, type ETagOptions } from "../deps.ts";
import type { Middleware } from "../middleware.ts";
import { BODY_TYPES } from "../utils/consts.ts";
import { isAsyncIterable, isReader } from "../utils/type_guards.ts";

// This is to work around issue introduced in Deno 1.40
// See: https://github.com/denoland/deno/issues/22115
Expand Down
17 changes: 8 additions & 9 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,22 @@ export {
export type { BodyType } from "./body.ts";
export { Context, type ContextSendOptions } from "./context.ts";
export * as helpers from "./helpers.ts";
export * as etag from "./etag.ts";
export { Server as HttpServerNative } from "./http_server_native.ts";
export { type NativeRequest } from "./http_server_native_request.ts";
export { proxy } from "./middleware/proxy.ts";
export type { ProxyOptions } from "./middleware/proxy.ts";
export * as etag from "./middleware/etag.ts";
export { proxy, type ProxyOptions } from "./middleware/proxy.ts";
export {
route,
RouteContext,
serve,
ServeContext,
} from "./middleware/serve.ts";
export { compose as composeMiddleware } from "./middleware.ts";
export type {
Middleware,
MiddlewareObject,
MiddlewareOrMiddlewareObject,
Next,
export {
compose as composeMiddleware,
type Middleware,
type MiddlewareObject,
type MiddlewareOrMiddlewareObject,
type Next,
} from "./middleware.ts";
export { Request } from "./request.ts";
export { REDIRECT_BACK, Response } from "./response.ts";
Expand Down
11 changes: 5 additions & 6 deletions send.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import {

import type { Application } from "./application.ts";
import type { Context } from "./context.ts";
import { assert, errors } from "./deps.ts";
import * as etag from "./etag.ts";
import { assert, calculate, errors } from "./deps.ts";
import type { RouteParams } from "./router.ts";
import { send } from "./send.ts";
import { isNode } from "./utils/type_guards.ts";
Expand Down Expand Up @@ -323,7 +322,7 @@ Deno.test({
assertEquals(context.response.type, ".json");
assertStrictEquals(context.response.headers.get("content-encoding"), null);
const etagHeader = context.response.headers.get("etag");
assertEquals(etagHeader, await etag.calculate(fixture));
assertEquals(etagHeader, await calculate(fixture));
},
});

Expand Down Expand Up @@ -352,15 +351,15 @@ Deno.test({
async fn() {
const { context } = setup("/test.jpg");
const fixture = await Deno.readFile("./fixtures/test.jpg");
const ifNoneMatch = await etag.calculate(fixture);
const ifNoneMatch = await calculate(fixture);
assert(ifNoneMatch);
context.request.headers.set("If-None-Match", ifNoneMatch);
await send(context, context.request.url.pathname, { root: "./fixtures" });
const nativeResponse = await context.response.toDomResponse();
assertEquals(nativeResponse.status, 304);
assertEquals(
context.response.headers.get("etag"),
await etag.calculate(fixture),
await calculate(fixture),
);
},
});
Expand All @@ -381,7 +380,7 @@ Deno.test({
assertStrictEquals(context.response.headers.get("content-encoding"), null);
assertEquals(
context.response.headers.get("etag"),
await etag.calculate(fixture),
await calculate(fixture),
);
},
});
Expand Down
4 changes: 3 additions & 1 deletion send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
*/

import type { Context } from "./context.ts";
import { calculate, type FileInfo, ifNoneMatch } from "./etag.ts";
import {
basename,
type ByteRange,
calculate,
contentType,
createHttpError,
extname,
type FileInfo,
ifNoneMatch,
parse,
range,
readAll,
Expand Down

0 comments on commit 70e4cbf

Please sign in to comment.