Skip to content

Commit df9f326

Browse files
committed
minor improvements in http
`http`: breaking changes and minor improvements. Moved server-only HTTP header constants to server-only modules. `notFound` now uses named parameters. `LiveBroad..response` now uses named parameters. `HttpFile..response` now uses named parameters. Various response-generating functions and methods now support overriding the response class. `fileResponse` now supports "modified since" HTTP headers, returning a 304 response when a file hasn't been modified since the timestamp provided in the request, if any. However, file responses don't have the `last-modified` header by default. It can be set optionally. Fixed a bug in `fileResponse` where files with 304 responses were not registered with the provided live client, if any.
1 parent 4285209 commit df9f326

38 files changed

+489
-397
lines changed

.eslint.config.mjs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ export default [
7777
[`no-import-assign`]: `error`,
7878
[`no-inner-declarations`]: `error`,
7979
[`no-invalid-regexp`]: `error`,
80-
[`no-invalid-this`]: [`error`, {capIsConstructor: false}],
8180
[`no-irregular-whitespace`]: `error`,
8281
[`no-misleading-character-class`]: `error`,
8382
[`no-mixed-spaces-and-tabs`]: `error`,
@@ -110,7 +109,17 @@ export default [
110109
[`use-isnan`]: `error`,
111110
[`valid-typeof`]: `error`,
112111

113-
// [`quotes`]: [`error`, `backtick`], // Doesn't work properly.
112+
// Doesn't work properly.
113+
// [`quotes`]: [`error`, `backtick`],
114+
115+
/*
116+
There used to be a time and place for this rule. However, it can also lead
117+
to pitfalls. There are cases when separating a context object from a method
118+
is correct and useful, and enforcing "no this" can lead to mistakes, such
119+
as accidentally closuring an object which is meant to be referenced weakly
120+
via `WeakRef`.
121+
*/
122+
// [`no-invalid-this`]: [`error`, {capIsConstructor: false}],
114123
},
115124
},
116125
{

doc/prax_readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Short overview of features:
1515
* Convenient syntax. Nice-to-use in plain JS.
1616
* No templates.
1717
* No string parsing.
18-
* No need for JSX.
18+
* No need for JSX. (Compatible with it.)
1919
* No need for a build system.
2020
* Built-in reactivity with {{featLink obs}}.
2121
* Can use native [custom elements](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements) for state.

docs/cli_readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
CLI args:
2424

2525
```js
26-
import * as cl from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.82/cli.mjs'
26+
import * as cl from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.83/cli.mjs'
2727

2828
const cli = cl.Flag.os()
2929

@@ -34,15 +34,15 @@ console.log(...cli.args)
3434
Console clearing:
3535

3636
```js
37-
import * as cl from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.82/cli.mjs'
37+
import * as cl from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.83/cli.mjs'
3838

3939
cl.emptty()
4040
```
4141

4242
Clearing the console only once, before running your code:
4343

4444
```js
45-
import 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.82/cli_emptty.mjs'
45+
import 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.83/cli_emptty.mjs'
4646
```
4747

4848
## API

docs/coll_readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Port and rework of https://github.com/mitranim/jol.
2626
## Usage
2727

2828
```js
29-
import * as c from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.82/coll.mjs'
29+
import * as c from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.83/coll.mjs'
3030
```
3131

3232
## API
@@ -101,8 +101,8 @@ Links: [source](../coll.mjs#L100); [test/example](../test/coll_test.mjs#L218).
101101
Variant of [#`Bmap`](#class-bmap) with support for key and value checks. Subclasses must override methods `.reqKey` and `.reqVal`. These methods are automatically called by `.set`. Method `.reqKey` must validate and return the given key, and method `.reqVal` must validate and return the given value. Use type assertions provided by [`lang`](lang_readme.md).
102102

103103
```js
104-
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.82/lang.mjs'
105-
import * as c from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.82/coll.mjs'
104+
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.83/lang.mjs'
105+
import * as c from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.83/coll.mjs'
106106

107107
class StrNatMap extends c.TypedMap {
108108
reqKey(key) {return l.reqStr(key)}
@@ -242,7 +242,7 @@ Differences and advantages over `Array`:
242242
The overhead of the wrapper is insignificant.
243243

244244
```js
245-
import * as c from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.82/coll.mjs'
245+
import * as c from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.83/coll.mjs'
246246

247247
console.log(new c.Vec())
248248
// Vec{Symbol(val): []}

docs/dom_readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
## Usage
1212

1313
```js
14-
import * as d from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.82/dom.mjs'
14+
import * as d from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.83/dom.mjs'
1515
```
1616

1717
## API

docs/dom_reg_readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
Example mockup for a pushstate link.
2828

2929
```js
30-
import * as dr from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.82/dom_reg.mjs'
30+
import * as dr from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.83/dom_reg.mjs'
3131

3232
// Immediately ready for use. Tag is automatically set to `a-btn`.
3333
// The mixin `MixReg` enables automatic registration on instantiation.
@@ -66,7 +66,7 @@ Apps which use server-side rendering and client-side upgrading of custom element
6666
Instead, use `dr.reg`, which is also used internally by `MixReg`. This is simply a shortcut for using the [#default registry](#class-reg) provided by this module.
6767

6868
```js
69-
import * as dr from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.82/dom_reg.mjs'
69+
import * as dr from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.83/dom_reg.mjs'
7070

7171
class Btn extends HTMLButtonElement {
7272
/*
@@ -106,7 +106,7 @@ For browser-only code, prefer the mixin `MixReg` from the same module which is e
106106
Simple usage:
107107

108108
```js
109-
import * as dr from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.82/dom_reg.mjs'
109+
import * as dr from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.83/dom_reg.mjs'
110110

111111
class Btn extends HTMLButtonElement {
112112
/*
@@ -126,7 +126,7 @@ document.body.append(new Btn())
126126
You can unset the default definer to defer registration:
127127

128128
```js
129-
import * as dr from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.82/dom_reg.mjs'
129+
import * as dr from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.83/dom_reg.mjs'
130130

131131
dr.Reg.main.setDefiner()
132132

docs/dom_shim_readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
## Usage
1212

1313
```js
14-
import * as ds from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.82/dom_shim.mjs'
14+
import * as ds from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.83/dom_shim.mjs'
1515
```
1616

1717
## API

docs/http_bun_readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@ The following APIs are exported but undocumented. Check [http_bun.mjs](../http_b
8080
* [`function serve`](../http_bun.mjs#L9)
8181
* [`function srvUrl`](../http_bun.mjs#L18)
8282
* [`class HttpFile`](../http_bun.mjs#L20)
83-
* [`class HttpDir`](../http_bun.mjs#L46)
83+
* [`class HttpDir`](../http_bun.mjs#L48)

docs/http_deno_readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@ The following APIs are exported but undocumented. Check [http_deno.mjs](../http_
8080
* [`function serve`](../http_deno.mjs#L9)
8181
* [`function srvUrl`](../http_deno.mjs#L14)
8282
* [`class HttpFile`](../http_deno.mjs#L21)
83-
* [`class HttpDir`](../http_deno.mjs#L44)
83+
* [`class HttpDir`](../http_deno.mjs#L46)

docs/http_live_readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ The following APIs are exported but undocumented. Check [http_live.mjs](../http_
2323
* [`const LIVE_PATH_SEND`](../http_live.mjs#L17)
2424
* [`function liveScript`](../http_live.mjs#L21)
2525
* [`class LiveBroad`](../http_live.mjs#L25)
26-
* [`class LiveClient`](../http_live.mjs#L59)
27-
* [`function isResHtmlText`](../http_live.mjs#L119)
26+
* [`class LiveClient`](../http_live.mjs#L66)
27+
* [`function isResHtmlText`](../http_live.mjs#L125)

0 commit comments

Comments
 (0)