@vzn/vx-cache 0.0.651 → 0.0.652
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/package.json +2 -2
- package/src/index.ts +18 -6
package/README.md
CHANGED
|
@@ -31,7 +31,8 @@ export default {
|
|
|
31
31
|
|
|
32
32
|
- `url` is the server's base URL (`https://cache.example.com`, without `/v1`), or `VX_CACHE_URL`.
|
|
33
33
|
It must be `https://`: every request carries the CI token, so `http://`
|
|
34
|
-
is taken only to this machine (`127.0.0.1`, `::1`, `localhost`).
|
|
34
|
+
is taken only to this machine (`127.0.0.1`, `::1`, `localhost`). It
|
|
35
|
+
takes no `?query` or `#fragment`: each route is appended to it. The
|
|
35
36
|
option is checked when the config loads, `VX_CACHE_URL` when a run
|
|
36
37
|
opens the cache.
|
|
37
38
|
- `issuer` (the CI issuer's URL, as its tokens name it) and `repository`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vzn/vx-cache",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.652",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "vxCache(): a vx cache plugin for a server that speaks the vx-cache protocol, such as @vzn/vx-cache-server.",
|
|
6
6
|
"keywords": [
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"jose: the tests sign the CI tokens the server checks."
|
|
33
33
|
],
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@vzn/vx": "^0.0.
|
|
35
|
+
"@vzn/vx": "^0.0.652"
|
|
36
36
|
},
|
|
37
37
|
"repository": {
|
|
38
38
|
"type": "git",
|
package/src/index.ts
CHANGED
|
@@ -148,8 +148,12 @@ async function jsonUpTo(res: Response, max: number, what: string): Promise<unkno
|
|
|
148
148
|
|
|
149
149
|
/** Capabilities and a CI token are a few hundred bytes: room to spare. */
|
|
150
150
|
const SMALL_ANSWER_BYTES = 64 * 1024
|
|
151
|
-
/**
|
|
152
|
-
|
|
151
|
+
/**
|
|
152
|
+
* A check's answer per hash asked: a hash (up to 128), a size and a scope
|
|
153
|
+
* (up to 512, a long branch's) in JSON are under 700 bytes. At 512 an
|
|
154
|
+
* answer under the longest scopes was refused as too long.
|
|
155
|
+
*/
|
|
156
|
+
const CHECK_BYTES_PER_HASH = 1024
|
|
153
157
|
|
|
154
158
|
/**
|
|
155
159
|
* `s` with each C0/C1 control and DEL written as `\xNN`: a server's words
|
|
@@ -865,10 +869,12 @@ function shown(url: string): string {
|
|
|
865
869
|
* http:// to another host sent it in clear.
|
|
866
870
|
*/
|
|
867
871
|
function secure(url: string): boolean {
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
+
// Parsed as the request will be: a scheme in any case, no url it cannot carry.
|
|
873
|
+
const u = URL.parse(url)
|
|
874
|
+
if (u === null || u.host === '') return false
|
|
875
|
+
if (u.protocol === 'https:') return true
|
|
876
|
+
if (u.protocol !== 'http:') return false
|
|
877
|
+
return u.hostname === '127.0.0.1' || u.hostname === '[::1]' || u.hostname === 'localhost'
|
|
872
878
|
}
|
|
873
879
|
|
|
874
880
|
/** Options over `VX_CACHE_URL`; `undefined`: no server named. */
|
|
@@ -885,6 +891,12 @@ export function resolveVxCacheConfig(
|
|
|
885
891
|
throw new UserError(
|
|
886
892
|
`vxCache(): ${from} must be https (http only to 127.0.0.1, ::1 or localhost), got ${shown(url)}`,
|
|
887
893
|
)
|
|
894
|
+
// Each route is appended to the url: past a `?` or `#` it was query or
|
|
895
|
+
// fragment, and every request asked the server's root.
|
|
896
|
+
if (/[?#]/.test(url))
|
|
897
|
+
throw new UserError(
|
|
898
|
+
`vxCache(): ${from} takes no ?query or #fragment: each route is appended to it, got ${shown(url)}`,
|
|
899
|
+
)
|
|
888
900
|
// Each route is the url's /v1/…: one that names /v1 asked /v1/v1/…, and every answer was a 404.
|
|
889
901
|
if (url.endsWith('/v1'))
|
|
890
902
|
throw new UserError(
|