Skip to content

Commit ef6dfce

Browse files
Merge pull request #1 from httpland/beta
Beta
2 parents 7fca4eb + 55399bd commit ef6dfce

28 files changed

+1185
-4
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
pull_request:
9+
branches:
10+
- main
11+
12+
schedule:
13+
- cron: '18 15 * * 2'
14+
15+
jobs:
16+
analyze:
17+
name: Analyze
18+
runs-on: ubuntu-latest
19+
permissions:
20+
actions: read
21+
contents: read
22+
security-events: write
23+
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
language: [ 'typescript' ]
28+
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v3
32+
33+
- name: Initialize CodeQL
34+
uses: github/codeql-action/init@v2
35+
with:
36+
languages: ${{ matrix.language }}
37+
38+
- name: Autobuild
39+
uses: github/codeql-action/autobuild@v2
40+
41+
- name: Perform CodeQL Analysis
42+
uses: github/codeql-action/analyze@v2

.github/workflows/release-npm.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: release-npm
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
release:
9+
runs-on: ${{ matrix.os }}
10+
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest]
14+
deno: [v1.x]
15+
node: [16.x]
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v3
20+
21+
- uses: denoland/setup-deno@v1
22+
with:
23+
deno-version: ${{ matrix.deno }}
24+
25+
- name: Cache node_modules
26+
uses: actions/cache@v2
27+
with:
28+
path: ~/.pnpm-store
29+
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
30+
restore-keys: |
31+
${{ runner.os }}-
32+
33+
- uses: pnpm/[email protected]
34+
with:
35+
version: 6.23.6
36+
run_install: |
37+
- recursive: true
38+
args: [--frozen-lockfile, --prefer-offline, --ignore-scripts]
39+
40+
- name: Get tag version
41+
if: startsWith(github.ref, 'refs/tags/')
42+
id: get_tag_version
43+
run: echo ::set-output name=TAG_VERSION::${GITHUB_REF/refs\/tags\//}
44+
45+
- uses: actions/setup-node@v2
46+
with:
47+
node-version: ${{ matrix.node }}
48+
registry-url: 'https://registry.npmjs.org'
49+
50+
- name: build
51+
run: deno run -A ./_tools/build_npm.ts ${{steps.get_tag_version.outputs.TAG_VERSION}}
52+
53+
- name: publish
54+
env:
55+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
56+
run: deno run -A ./_tools/publish_npm.ts ${{steps.get_tag_version.outputs.TAG_VERSION}}
57+

.github/workflows/release.yaml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: release
2+
3+
on:
4+
push:
5+
branches:
6+
- beta
7+
- main
8+
9+
jobs:
10+
lint:
11+
runs-on: ${{ matrix.os }}
12+
13+
strategy:
14+
matrix:
15+
os: [ubuntu-latest]
16+
deno: [v1.x]
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v3
21+
22+
- uses: denoland/setup-deno@v1
23+
with:
24+
deno-version: ${{ matrix.deno }}
25+
26+
- name: Lint
27+
run: |
28+
deno fmt --check
29+
deno lint
30+
31+
test:
32+
runs-on: ${{ matrix.os }}
33+
34+
strategy:
35+
matrix:
36+
os: [ubuntu-latest]
37+
deno: [v1.x]
38+
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@v3
42+
43+
- uses: denoland/setup-deno@v1
44+
with:
45+
deno-version: ${{ matrix.deno }}
46+
47+
- name: Test
48+
run: deno task test --coverage=coverage
49+
50+
- name: Generate coverage
51+
run: deno coverage coverage --output=cov_profile.lcov --lcov
52+
53+
- uses: codecov/codecov-action@v3
54+
with:
55+
files: cov_profile.lcov
56+
57+
release:
58+
needs: [lint, test]
59+
runs-on: ${{ matrix.os }}
60+
61+
strategy:
62+
matrix:
63+
os: [ubuntu-latest]
64+
65+
steps:
66+
- name: Checkout
67+
uses: actions/checkout@v3
68+
with:
69+
token: ${{ secrets.GH_TOKEN }}
70+
71+
- uses: cycjimmy/semantic-release-action@v3
72+
with:
73+
extra_plugins: |
74+
@semantic-release/changelog
75+
@semantic-release/git
76+
env:
77+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

.github/workflows/test.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: test
2+
3+
on: push
4+
jobs:
5+
lint:
6+
runs-on: ${{ matrix.os }}
7+
8+
strategy:
9+
matrix:
10+
os: [ubuntu-latest, ubuntu-22.04, macos-latest, windows-latest]
11+
deno: [v1.x]
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v3
16+
17+
- uses: denoland/setup-deno@v1
18+
with:
19+
deno-version: ${{ matrix.deno }}
20+
21+
- name: Lint
22+
run: |
23+
deno fmt --check
24+
deno lint
25+
26+
test:
27+
runs-on: ${{ matrix.os }}
28+
29+
strategy:
30+
matrix:
31+
os: [ubuntu-latest, ubuntu-22.04, macos-latest, windows-latest]
32+
deno: [v1.x]
33+
34+
steps:
35+
- name: Checkout
36+
uses: actions/checkout@v3
37+
38+
- uses: denoland/setup-deno@v1
39+
with:
40+
deno-version: ${{ matrix.deno }}
41+
42+
- name: Test
43+
run: deno task test

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# [1.0.0-beta.2](https://github.com/httpland/compression-middleware/compare/1.0.0-beta.1...1.0.0-beta.2) (2023-03-19)
2+
3+
4+
### Features
5+
6+
* **middleware:** change interface to accept iterable encoder ([008780f](https://github.com/httpland/compression-middleware/commit/008780fda4c82673721800007ea39fbf5015eaf9))
7+
* **mod:** export types for middleware ([7d785b8](https://github.com/httpland/compression-middleware/commit/7d785b881aa025ec13d9a2282cc2765e97770038))
8+
9+
# 1.0.0-beta.1 (2023-03-19)
10+
11+
12+
### Bug Fixes
13+
14+
* **middleware:** add checking duplicated vary field value ([ed76914](https://github.com/httpland/compression-middleware/commit/ed76914b2bb459e49edfbf0b9096b2740e4c8e7a))
15+
16+
17+
### Features
18+
19+
* add factory for compression middleware ([551fb4d](https://github.com/httpland/compression-middleware/commit/551fb4d3d5979b6c1c89efff7b5e7da5a3f60523))
20+
* **encoders:** add preset encoders ([faf1c51](https://github.com/httpland/compression-middleware/commit/faf1c51549c75ac16b1658693f7a7d68c300e74f))
21+
* **middleware:** accept encoder like object ([94aa46a](https://github.com/httpland/compression-middleware/commit/94aa46a9f74cc69534ed802616125f5e2486376e))
22+
* **transform:** add checking cache-control header ([0c99ac0](https://github.com/httpland/compression-middleware/commit/0c99ac0cd7175f5b0fc086c597a431730bc05a59))
23+
* **transform:** add re-calculataion of content-length header ([61886b9](https://github.com/httpland/compression-middleware/commit/61886b9b1386f3c33c388873852bd291ab0653a2))
24+
* **types:** export types for encoding ([0673679](https://github.com/httpland/compression-middleware/commit/06736794ea43160071b309d46c71f72fe384830a))

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
MIT License
2+
3+
Copyright (c) 2023 httpland
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,15 @@ Content-Encoding: <encoding>
5858
Vary: accept-encoding
5959
```
6060

61-
## Additional encoding
61+
## Built-in encoding
6262

63-
By default, middleware supports the following encodings:
63+
Middleware supports the following encodings by default:
6464

6565
- gzip
6666
- deflate
6767

68+
## Additional encoding
69+
6870
You can add supported encoding.
6971

7072
There are two ways to add encodings:
@@ -112,8 +114,8 @@ Example of adding `brotli` encoding:
112114
```ts
113115
import {
114116
compression,
117+
type Encode,
115118
type Encoder,
116-
type EncodingMap,
117119
} from "https://deno.land/x/compression_middleware@$VERSION/mod.ts";
118120

119121
declare const encodeBr: Encode;
@@ -128,7 +130,7 @@ const middleware = compression([Br]);
128130

129131
```ts
130132
interface Encode {
131-
(stream: ReadableStream<Unit8Array>): BodyInit | Promise<BodyInit>;
133+
(stream: ReadableStream<Uint8Array>): BodyInit | Promise<BodyInit>;
132134
}
133135
```
134136

@@ -148,6 +150,30 @@ compressible.
148150
For example, image media such as `image/jpag` is not compressible because it is
149151
already compressed.
150152

153+
## Content-Length
154+
155+
If the Response has a `Content-Length` header, compression may cause the actual
156+
content length to deviate.
157+
158+
In that case, the `Content-Length` is recalculated.
159+
160+
```ts
161+
import { compression } from "https://deno.land/x/compression_middleware@$VERSION/mod.ts";
162+
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
163+
164+
declare const request: Request;
165+
const middleware = compression();
166+
167+
const response = await middleware(
168+
request,
169+
() =>
170+
new Response("<body>", { headers: { "content-length": "<body:length>" } }),
171+
);
172+
173+
assertEquals(await response.text(), "<gzip:body>");
174+
assertEquals(response.headers.get("content-length"), "<gzip:body:length>");
175+
```
176+
151177
## Effects
152178

153179
Middleware may make changes to the following elements of the HTTP message.
@@ -156,6 +182,7 @@ Middleware may make changes to the following elements of the HTTP message.
156182
- HTTP Headers
157183
- Content-Encoding
158184
- Vary
185+
- [Content-Length](#content-length)
159186

160187
## Conditions
161188

_dev_deps.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export {
2+
assert,
3+
assertEquals,
4+
assertFalse,
5+
assertThrows,
6+
} from "https://deno.land/[email protected]/testing/asserts.ts";
7+
export { describe, it } from "https://deno.land/[email protected]/testing/bdd.ts";
8+
export {
9+
assertSpyCalls,
10+
spy,
11+
} from "https://deno.land/[email protected]/testing/mock.ts";
12+
export { equalsResponse } from "https://deno.land/x/[email protected]/response.ts";

_test_import_map.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"imports": {
3+
"https://deno.land/x/compression_middleware@$VERSION/": "./"
4+
}
5+
}

_tools/build_npm.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { build, emptyDir } from "https://deno.land/x/[email protected]/mod.ts";
2+
import { join } from "https://deno.land/[email protected]/path/mod.ts";
3+
import { makeOptions } from "./meta.ts";
4+
5+
async function buildPkg(version: string): Promise<void> {
6+
await emptyDir("./npm");
7+
const pkg = makeOptions(version);
8+
await Deno.copyFile("LICENSE", join(pkg.outDir, "LICENSE"));
9+
Deno.copyFile(
10+
join(".", "README.md"),
11+
join(pkg.outDir, "README.md"),
12+
);
13+
await build(pkg);
14+
}
15+
16+
if (import.meta.main) {
17+
const version = Deno.args[0];
18+
if (!version) {
19+
console.error("argument is required");
20+
Deno.exit(1);
21+
}
22+
await buildPkg(version);
23+
}

0 commit comments

Comments
 (0)