diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d104f0d..b749a8d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,7 +10,10 @@ on: jobs: test: - runs-on: ubuntu-latest + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 - uses: denoland/setup-deno@v1.1.1 @@ -21,6 +24,7 @@ jobs: - name: Create coverage report run: deno task cov - name: Coveralls + if: ${{ matrix.os == 'ubuntu-latest' }} uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/deno.lock b/deno.lock index 10522af..f0a88c5 100644 --- a/deno.lock +++ b/deno.lock @@ -1,6 +1,8 @@ { "version": "2", "remote": { + "https://cdn.skypack.dev/-/@tinyhttp/content-disposition@v2.1.0-mVxRSOF3zZTQVpyfceQU/dist=es2019,mode=imports/optimized/@tinyhttp/content-disposition.js": "86b978e239324154099ed0c88c0ea07c025c8639c4170b94a934e695bdb6ae86", + "https://cdn.skypack.dev/@tinyhttp/content-disposition@2.1.0": "5e66ec22cb0e0434e0d0f845aa3dc9eee5f210cc480b3542af90adbb68c5fabf", "https://deno.land/std@0.106.0/fmt/colors.ts": "d2f8355f00a74404668fc5a1e4a92983ce1a9b0a6ac1d40efbd681cb8f519586", "https://deno.land/std@0.182.0/fmt/colors.ts": "d67e3cd9f472535241a8e410d33423980bec45047e343577554d3356e1f0ef4e", "https://deno.land/std@0.182.0/testing/_diff.ts": "1a3c044aedf77647d6cac86b798c6417603361b66b54c53331b312caeb447aea", @@ -18,25 +20,7 @@ "https://deno.land/std@0.185.0/async/pool.ts": "fd082bd4aaf26445909889435a5c74334c017847842ec035739b4ae637ae8260", "https://deno.land/std@0.185.0/async/retry.ts": "dd19d93033d8eaddbfcb7654c0366e9d3b0a21448bdb06eba4a7d8a8cf936a92", "https://deno.land/std@0.185.0/async/tee.ts": "47e42d35f622650b02234d43803d0383a89eb4387e1b83b5a40106d18ae36757", - "https://deno.land/std@0.185.0/datetime/to_imf.ts": "8f9c0af8b167031ffe2e03da01a12a3b0672cc7562f89c61942a0ab0129771b2", - "https://deno.land/std@0.185.0/encoding/base64.ts": "144ae6234c1fbe5b68666c711dc15b1e9ee2aef6d42b3b4345bf9a6c91d70d0d", - "https://deno.land/std@0.185.0/http/_negotiation/common.ts": "14d1a52427ab258a4b7161cd80e1d8a207b7cc64b46e911780f57ead5f4323c6", - "https://deno.land/std@0.185.0/http/_negotiation/encoding.ts": "ff747d107277c88cb7a6a62a08eeb8d56dad91564cbcccb30694d5dc126dcc53", - "https://deno.land/std@0.185.0/http/_negotiation/language.ts": "7bcddd8db3330bdb7ce4fc00a213c5547c1968139864201efd67ef2d0d51887d", - "https://deno.land/std@0.185.0/http/_negotiation/media_type.ts": "58847517cd549384ad677c0fe89e0a4815be36fe7a303ea63cee5f6a1d7e1692", - "https://deno.land/std@0.185.0/http/cookie.ts": "934f92d871d50852dbd7a836d721df5a9527b14381db16001b40991d30174ee4", - "https://deno.land/std@0.185.0/http/cookie_map.ts": "d148a5eaf35f19905dd5104126fa47ac71105306dd42f129732365e43108b28a", - "https://deno.land/std@0.185.0/http/http_status.ts": "8a7bcfe3ac025199ad804075385e57f63d055b2aed539d943ccc277616d6f932", - "https://deno.land/std@0.185.0/http/negotiation.ts": "46e74a6bad4b857333a58dc5b50fe8e5a4d5267e97292293ea65f980bd918086", "https://deno.land/std@0.185.0/http/server.ts": "cbb17b594651215ba95c01a395700684e569c165a567e4e04bba327f41197433", - "https://deno.land/std@0.185.0/media_types/_db.ts": "7606d83e31f23ce1a7968cbaee852810c2cf477903a095696cdc62eaab7ce570", - "https://deno.land/std@0.185.0/media_types/_util.ts": "916efbd30b6148a716f110e67a4db29d6949bf4048997b754415dd7e42c52378", - "https://deno.land/std@0.185.0/media_types/content_type.ts": "ad98a5aa2d95f5965b2796072284258710a25e520952376ed432b0937ce743bc", - "https://deno.land/std@0.185.0/media_types/format_media_type.ts": "f5e1073c05526a6f5a516ac5c5587a1abd043bf1039c71cde1166aa4328c8baf", - "https://deno.land/std@0.185.0/media_types/get_charset.ts": "18b88274796fda5d353806bf409eb1d2ddb3f004eb4bd311662c4cdd8ac173db", - "https://deno.land/std@0.185.0/media_types/parse_media_type.ts": "835c4112e1357e95b4f10d7cdea5ae1801967e444f48673ff8f1cb4d32af9920", - "https://deno.land/std@0.185.0/media_types/type_by_extension.ts": "daa801eb0f11cdf199445d0f1b656cf116d47dcf9e5b85cc1e6b4469f5ee0432", - "https://deno.land/std@0.185.0/media_types/vendor/mime-db.v1.52.0.ts": "6925bbcae81ca37241e3f55908d0505724358cda3384eaea707773b2c7e99586", "https://deno.land/std@0.185.0/path/_constants.ts": "e49961f6f4f48039c0dfed3c3f93e963ca3d92791c9d478ac5b43183413136e0", "https://deno.land/std@0.185.0/path/_interface.ts": "6471159dfbbc357e03882c2266d21ef9afdb1e4aa771b0545e90db58a0ba314b", "https://deno.land/std@0.185.0/path/_util.ts": "d7abb1e0dea065f427b89156e28cdeb32b045870acdf865833ba808a73b576d0", @@ -46,6 +30,35 @@ "https://deno.land/std@0.185.0/path/posix.ts": "8b7c67ac338714b30c816079303d0285dd24af6b284f7ad63da5b27372a2c94d", "https://deno.land/std@0.185.0/path/separator.ts": "0fb679739d0d1d7bf45b68dacfb4ec7563597a902edbaf3c59b50d5bcadd93b1", "https://deno.land/std@0.185.0/path/win32.ts": "d186344e5583bcbf8b18af416d13d82b35a317116e6460a5a3953508c3de5bba", + "https://deno.land/std@0.192.0/_util/asserts.ts": "178dfc49a464aee693a7e285567b3d0b555dc805ff490505a8aae34f9cfb1462", + "https://deno.land/std@0.192.0/_util/os.ts": "d932f56d41e4f6a6093d56044e29ce637f8dcc43c5a90af43504a889cf1775e3", + "https://deno.land/std@0.192.0/datetime/to_imf.ts": "8f9c0af8b167031ffe2e03da01a12a3b0672cc7562f89c61942a0ab0129771b2", + "https://deno.land/std@0.192.0/encoding/base64.ts": "144ae6234c1fbe5b68666c711dc15b1e9ee2aef6d42b3b4345bf9a6c91d70d0d", + "https://deno.land/std@0.192.0/http/_negotiation/common.ts": "14d1a52427ab258a4b7161cd80e1d8a207b7cc64b46e911780f57ead5f4323c6", + "https://deno.land/std@0.192.0/http/_negotiation/encoding.ts": "ff747d107277c88cb7a6a62a08eeb8d56dad91564cbcccb30694d5dc126dcc53", + "https://deno.land/std@0.192.0/http/_negotiation/language.ts": "7bcddd8db3330bdb7ce4fc00a213c5547c1968139864201efd67ef2d0d51887d", + "https://deno.land/std@0.192.0/http/_negotiation/media_type.ts": "58847517cd549384ad677c0fe89e0a4815be36fe7a303ea63cee5f6a1d7e1692", + "https://deno.land/std@0.192.0/http/cookie.ts": "934f92d871d50852dbd7a836d721df5a9527b14381db16001b40991d30174ee4", + "https://deno.land/std@0.192.0/http/cookie_map.ts": "d148a5eaf35f19905dd5104126fa47ac71105306dd42f129732365e43108b28a", + "https://deno.land/std@0.192.0/http/http_status.ts": "8a7bcfe3ac025199ad804075385e57f63d055b2aed539d943ccc277616d6f932", + "https://deno.land/std@0.192.0/http/negotiation.ts": "46e74a6bad4b857333a58dc5b50fe8e5a4d5267e97292293ea65f980bd918086", + "https://deno.land/std@0.192.0/media_types/_db.ts": "7606d83e31f23ce1a7968cbaee852810c2cf477903a095696cdc62eaab7ce570", + "https://deno.land/std@0.192.0/media_types/_util.ts": "916efbd30b6148a716f110e67a4db29d6949bf4048997b754415dd7e42c52378", + "https://deno.land/std@0.192.0/media_types/content_type.ts": "ad98a5aa2d95f5965b2796072284258710a25e520952376ed432b0937ce743bc", + "https://deno.land/std@0.192.0/media_types/format_media_type.ts": "f5e1073c05526a6f5a516ac5c5587a1abd043bf1039c71cde1166aa4328c8baf", + "https://deno.land/std@0.192.0/media_types/get_charset.ts": "18b88274796fda5d353806bf409eb1d2ddb3f004eb4bd311662c4cdd8ac173db", + "https://deno.land/std@0.192.0/media_types/parse_media_type.ts": "835c4112e1357e95b4f10d7cdea5ae1801967e444f48673ff8f1cb4d32af9920", + "https://deno.land/std@0.192.0/media_types/type_by_extension.ts": "daa801eb0f11cdf199445d0f1b656cf116d47dcf9e5b85cc1e6b4469f5ee0432", + "https://deno.land/std@0.192.0/media_types/vendor/mime-db.v1.52.0.ts": "6925bbcae81ca37241e3f55908d0505724358cda3384eaea707773b2c7e99586", + "https://deno.land/std@0.192.0/path/_constants.ts": "e49961f6f4f48039c0dfed3c3f93e963ca3d92791c9d478ac5b43183413136e0", + "https://deno.land/std@0.192.0/path/_interface.ts": "6471159dfbbc357e03882c2266d21ef9afdb1e4aa771b0545e90db58a0ba314b", + "https://deno.land/std@0.192.0/path/_util.ts": "d7abb1e0dea065f427b89156e28cdeb32b045870acdf865833ba808a73b576d0", + "https://deno.land/std@0.192.0/path/common.ts": "ee7505ab01fd22de3963b64e46cff31f40de34f9f8de1fff6a1bd2fe79380000", + "https://deno.land/std@0.192.0/path/glob.ts": "d479e0a695621c94d3fd7fe7abd4f9499caf32a8de13f25073451c6ef420a4e1", + "https://deno.land/std@0.192.0/path/mod.ts": "f065032a7189404fdac3ad1a1551a9ac84751d2f25c431e101787846c86c79ef", + "https://deno.land/std@0.192.0/path/posix.ts": "8b7c67ac338714b30c816079303d0285dd24af6b284f7ad63da5b27372a2c94d", + "https://deno.land/std@0.192.0/path/separator.ts": "0fb679739d0d1d7bf45b68dacfb4ec7563597a902edbaf3c59b50d5bcadd93b1", + "https://deno.land/std@0.192.0/path/win32.ts": "d186344e5583bcbf8b18af416d13d82b35a317116e6460a5a3953508c3de5bba", "https://deno.land/std@0.97.0/_util/assert.ts": "2f868145a042a11d5ad0a3c748dcf580add8a0dbc0e876eaa0026303a5488f58", "https://deno.land/std@0.97.0/_util/os.ts": "e282950a0eaa96760c0cf11e7463e66babd15ec9157d4c9ed49cc0925686f6a7", "https://deno.land/std@0.97.0/fmt/colors.ts": "db22b314a2ae9430ae7460ce005e0a7130e23ae1c999157e3bb77cf55800f7e4", @@ -109,7 +122,6 @@ "https://deno.land/x/status@0.1.0/codes.ts": "4770829290f22ec25af4db680cc05db6ae2248540e66998637b036fda0717254", "https://deno.land/x/status@0.1.0/maps.ts": "74d51c705716efc58d4110837b988579134ad07da4ed64c99b7443bea43eac95", "https://deno.land/x/status@0.1.0/status.ts": "5252fa9cf5fe13f10d97a273b8461d4ae88ed66ec3e3af90b04775cae224084d", - "https://deno.land/x/superfetch@1.0.4/types.ts": "6f4cc8eb685320002138980dd0893f5eeafe2a9725c8918f8dc21743f99e6b18", "https://deno.land/x/superfetch@1.0.5/deps.ts": "b5dd86d0dfc0d6c5b853bc183657778999c39970d256d67746b1f26f3753cfa6", "https://deno.land/x/superfetch@1.0.5/mod.ts": "1e7401ac3c0827e9a6e87d4d5c0994fa7e9ed4d7f67e0f60423b3f085478a1c5", "https://deno.land/x/superfetch@1.0.5/types.ts": "6f4cc8eb685320002138980dd0893f5eeafe2a9725c8918f8dc21743f99e6b18", @@ -124,11 +136,8 @@ "https://deno.land/x/tincan@1.0.1/src/reporter.ts": "84e09297da18c840076be951c02c749678b75dc89b2575f34db1378cbb509939", "https://deno.land/x/tincan@1.0.1/src/runner.ts": "54e1a0934a52469437bd4655df51f0c9148327d94a2b0d6c175f6f992a697b86", "https://deno.land/x/vary@1.0.0/mod.ts": "e7c452694b21336419f16e0891f8ea503adaafc7bde956fb29e1a86f450a68e6", - "https://esm.sh/@tinyhttp/content-disposition@2.0.9": "e422dc24d87d68690b2006d05fdf533bc9861fb60f44cc252b5de869455624c4", - "https://esm.sh/ipaddr.js@2.0.1": "b35c92d6f96eb8f3696f7bca3b2a9127e0c25c862096988d224d244d12bbf32c", - "https://esm.sh/v126/@tinyhttp/content-disposition@2.0.9/deno/content-disposition.mjs": "ee7f64a29f0d2f838e0b66de805b380e1b65b215af4704633f7767543f297e12", - "https://esm.sh/v126/@tinyhttp/content-disposition@2.0.9/dist/index.d.ts": "6d54da4270da92bf75e444a0d7d54ccbd71fcca5bb69916e3edd696985f985ac", - "https://esm.sh/v126/ipaddr.js@2.0.1/deno/ipaddr.mjs": "774ed6749a35b0e19baf8c37eeadb7972827caf8eb42c67781326c8a55566117", + "https://esm.sh/ipaddr.js@2.0.1": "fcbbbfbe9b3ef0896c04ccf197bf5b293cdc2d4d1c2c5d0f5e899cd31c884cce", + "https://esm.sh/v126/ipaddr.js@2.0.1/denonext/ipaddr.mjs": "89b0e479231c6f0e41e47786b3e84fea90cfa2f7f61789c3574378c4ab275cd8", "https://esm.sh/v126/ipaddr.js@2.0.1/lib/ipaddr.js.d.ts": "0a2a9ccd1ad8d5d9183182641c1d1b36e4912521074a063eaa7a09b973735cc5" } } diff --git a/deps.ts b/deps.ts index 87d89f6..9be5edf 100644 --- a/deps.ts +++ b/deps.ts @@ -1,9 +1,9 @@ export { parse as parseRange } from 'https://deno.land/x/range_parser@1.2.0/parse.ts' export type { RangesSpecifier } from 'https://deno.land/x/range_parser@1.2.0/types.ts' -export { typeByExtension } from 'https://deno.land/std@0.185.0/media_types/type_by_extension.ts' -export { getCharset } from 'https://deno.land/std@0.185.0/media_types/get_charset.ts' -export { contentType } from 'https://deno.land/std@0.185.0/media_types/content_type.ts' -export * as path from 'https://deno.land/std@0.185.0/path/mod.ts' +export { typeByExtension } from 'https://deno.land/std@0.192.0/media_types/type_by_extension.ts' +export { getCharset } from 'https://deno.land/std@0.192.0/media_types/get_charset.ts' +export { contentType } from 'https://deno.land/std@0.192.0/media_types/content_type.ts' +export * as path from 'https://deno.land/std@0.192.0/path/mod.ts' export { default as Negotiator } from 'https://deno.land/x/negotiator@1.0.1/mod.ts' export { vary } from 'https://deno.land/x/vary@1.0.0/mod.ts' export { encodeUrl } from 'https://deno.land/x/encodeurl@1.0.0/mod.ts' @@ -15,20 +15,20 @@ export { export { status } from 'https://deno.land/x/status@0.1.0/status.ts' export { isIP } from 'https://deno.land/x/isIP@1.0.0/mod.ts' export { escapeHtml } from 'https://deno.land/x/escape_html@1.0.0/mod.ts' -export * as base64 from 'https://deno.land/std@0.185.0/encoding/base64.ts' -export { parseMediaType } from 'https://deno.land/std@0.185.0/media_types/parse_media_type.ts' +export * as base64 from 'https://deno.land/std@0.192.0/encoding/base64.ts' +export { parseMediaType } from 'https://deno.land/std@0.192.0/media_types/parse_media_type.ts' export * as mediaTyper from 'https://deno.land/x/media_typer@1.0.1/mod.ts' -export { contentDisposition } from 'https://esm.sh/@tinyhttp/content-disposition@2.0.9' -export { basename, extname } from 'https://deno.land/std@0.185.0/path/mod.ts' +export { contentDisposition } from 'https://cdn.skypack.dev/@tinyhttp/content-disposition@2.1.0' +export { basename, extname } from 'https://deno.land/std@0.192.0/path/mod.ts' export { accepts, acceptsEncodings, acceptsLanguages, -} from 'https://deno.land/std@0.185.0/http/negotiation.ts' -export { setCookie } from 'https://deno.land/std@0.185.0/http/cookie.ts' -export type { Cookie } from 'https://deno.land/std@0.185.0/http/cookie.ts' +} from 'https://deno.land/std@0.192.0/http/negotiation.ts' +export { setCookie } from 'https://deno.land/std@0.192.0/http/cookie.ts' +export type { Cookie } from 'https://deno.land/std@0.192.0/http/cookie.ts' export { Status, STATUS_TEXT, -} from 'https://deno.land/std@0.185.0/http/http_status.ts' -export { CookieMap } from 'https://deno.land/std@0.185.0/http/cookie_map.ts' +} from 'https://deno.land/std@0.192.0/http/http_status.ts' +export { CookieMap } from 'https://deno.land/std@0.192.0/http/cookie_map.ts' diff --git a/examples/eta/mod.ts b/examples/eta/mod.ts index e88b08b..88d1316 100644 --- a/examples/eta/mod.ts +++ b/examples/eta/mod.ts @@ -1,30 +1,20 @@ -import { renderFileAsync } from 'https://deno.land/x/eta@v2.0.1/mod.ts' -import type { EtaConfig } from 'https://deno.land/x/eta@v2.0.1/config.ts' +import { Eta } from 'https://deno.land/x/eta@v3.0.3/src/index.ts' +import type { EtaConfig } from 'https://deno.land/x/eta@v3.0.3/src/config.ts' import { App } from '../../mod.ts' +import { path } from '../../deps.ts' +const eta = new Eta({ + views: path.join(Deno.cwd(), 'views'), +}) const app = new App() -app.engine('eta', renderFileAsync) - -function func() { - return new Promise((resolve) => { - setTimeout(() => { - resolve('HI FROM ASYNC') - }, 20) - }) -} - app.use( - async (_, res) => { - await res.render( - 'index.eta', - { name: 'Eta', func }, - { - renderOptions: { - async: true, - cache: true, - }, - }, + (_, res) => { + res.end( + eta.render( + 'index', + { name: 'Eta' }, + ), ) }, ) diff --git a/examples/eta/views/index.eta b/examples/eta/views/index.eta index 3e31a4a..c8eac20 100644 --- a/examples/eta/views/index.eta +++ b/examples/eta/views/index.eta @@ -1,3 +1 @@ -Hello from <%= it.name %> - -Async func: <%= await it.func() %> \ No newline at end of file +Hello from <%= it.name %> \ No newline at end of file diff --git a/examples/https/mod.ts b/examples/https/mod.ts index 2499d2b..0ee562a 100644 --- a/examples/https/mod.ts +++ b/examples/https/mod.ts @@ -1,5 +1,5 @@ import { App } from '../../app.ts' -import { serveTls } from 'https://deno.land/std@0.185.0/http/server.ts' +import { serveTls } from 'https://deno.land/std@0.192.0/http/server.ts' const app = new App() diff --git a/extensions/res/send/send.ts b/extensions/res/send/send.ts index 17d285c..5ae89f4 100644 --- a/extensions/res/send/send.ts +++ b/extensions/res/send/send.ts @@ -3,48 +3,53 @@ import { json } from './json.ts' import { createETag, setCharset } from '../utils.ts' import { end } from './end.ts' +const isBuffer = (body: unknown) => + body instanceof Uint8Array || body instanceof Blob || + body instanceof ArrayBuffer || body instanceof ReadableStream + export const send = < Req extends Request & { fresh?: boolean } = Request & { fresh?: boolean }, Res extends DummyResponse = DummyResponse, >(req: Req, res: Res) => async (body: unknown) => { let bodyToSend = body - // in case of object - turn it to json - if (ArrayBuffer.isView(body)) { - body = bodyToSend - } else if (typeof bodyToSend === 'object' && bodyToSend !== null) { + if (isBuffer(body)) { + bodyToSend = body + } else if (typeof body === 'object' && body !== null) { + // in case of object - turn it to json bodyToSend = JSON.stringify(body, null, 2) res._init.headers?.set('Content-Type', 'application/json') - } else { - if (typeof bodyToSend === 'string') { - // reflect this in content-type - const type = res._init.headers?.get('Content-Type') + } else if (typeof body === 'string') { + // reflect this in content-type + const type = res._init.headers.get('Content-Type') - if (type && typeof type === 'string') { - res._init.headers?.set('Content-Type', setCharset(type)) - } else {res._init.headers?.set( - 'Content-Type', - setCharset('text/html'), - )} - } + if (type && typeof type === 'string') { + res._init.headers.set('Content-Type', setCharset(type)) + } else {res._init.headers.set( + 'Content-Type', + setCharset('text/html'), + )} } - // populate ETag let etag: string | undefined if ( - bodyToSend && !res._init.headers?.get('etag') && - (etag = await createETag(bodyToSend as string)) + typeof body === 'string' && !res._init.headers.get('etag') ) { - res._init.headers?.set('etag', etag) + etag = await createETag(bodyToSend as string) } + { + if (etag) res._init.headers.set('etag', etag!) + } + // freshness if (req.fresh) res._init.status = 304 + // strip irrelevant headers if (res._init.status === 204 || res._init.status === 304) { - res._init.headers?.delete('Content-Type') - res._init.headers?.delete('Content-Length') - res._init.headers?.delete('Transfer-Encoding') + res._init.headers.delete('Content-Type') + res._init.headers.delete('Content-Length') + res._init.headers.delete('Transfer-Encoding') bodyToSend = '' } @@ -52,24 +57,18 @@ async (body: unknown) => { return end(res)(bodyToSend as BodyInit) } - if (typeof bodyToSend === 'object') { + if (typeof body === 'object') { if (body == null) { - return end(res)('') - } else if ( - bodyToSend instanceof Uint8Array || bodyToSend instanceof File - ) { - if (!res._init.headers?.get('Content-Type')) { + return end(res)(null) + } else if (isBuffer(body)) { + if (!res._init.headers.get('Content-Type')) { res._init.headers.set('content-type', 'application/octet-stream') } - return end(res)(bodyToSend) - } else { - return json(res)(bodyToSend) - } - } else { - if (typeof bodyToSend !== 'string' && bodyToSend) { - bodyToSend = (bodyToSend as string).toString() - } - - return end(res)(bodyToSend as BodyInit) + return end(res)(bodyToSend as BodyInit) + } else return json(res)(bodyToSend) + } + if (typeof bodyToSend !== 'string') { + bodyToSend = (bodyToSend as string).toString() } + return end(res)(bodyToSend as string) } diff --git a/tests/modules/send.test.ts b/tests/modules/send.test.ts index d9aed1b..5ef465c 100644 --- a/tests/modules/send.test.ts +++ b/tests/modules/send.test.ts @@ -3,6 +3,8 @@ import { json, send, sendStatus, status } from '../../extensions/res/mod.ts' import { runServer } from '../util.test.ts' import { App } from '../../mod.ts' +const te = new TextEncoder() + describe('json(body)', () => { it('should send a JSON reply when an object is passed', async () => { const app = runServer((_, res) => { @@ -118,12 +120,11 @@ describe('send(body)', () => { .expectHeader('Content-Type', null) .expectHeader('Transfer-Encoding', null) }) - it.skip('should set Content-Type to application/octet-stream for buffers if the header hasn\'t been set before', async () => { - const app = runServer((req, res) => - send(req, res)( - new TextEncoder().encode('Hello World'), - ) as unknown as Response - ) + it('should set Content-Type to application/octet-stream for buffers if the header hasn\'t been set before', async () => { + const app = runServer(async (req, res) => { + const r = await send(req, res)(te.encode('Hello World')) + return new Response(r._body, r._init) + }) const res = await makeFetch(app)('/') res.expectHeader( diff --git a/tests/util.test.ts b/tests/util.test.ts index 2197c18..c03d4db 100644 --- a/tests/util.test.ts +++ b/tests/util.test.ts @@ -3,7 +3,7 @@ import type { THRequest } from '../request.ts' import type { DummyResponse, THResponse } from '../response.ts' import type { AppConstructor, Handler } from '../types.ts' import { makeFetch } from '../dev_deps.ts' -import { ConnInfo } from 'https://deno.land/x/superfetch@1.0.4/types.ts' +import type { ConnInfo } from 'https://deno.land/x/superfetch@1.0.5/types.ts' export const supertest = (app: App) => { const fetch = makeFetch((req, conn) => app.handler(req, conn)) diff --git a/types.ts b/types.ts index 0d79f07..8129e51 100644 --- a/types.ts +++ b/types.ts @@ -61,7 +61,7 @@ type TemplateFunc = ( path: string, locals: Record, opts: TemplateEngineOptions, -) => Promise +) => string | Promise export interface ConnInfo { /** The local address of the connection. */