Skip to content

Commit 4e2e3b7

Browse files
committed
fast compression; put init_path; loop on del_id
1 parent 527771d commit 4e2e3b7

File tree

2 files changed

+73
-43
lines changed

2 files changed

+73
-43
lines changed

fastcaddy/core.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def init_path(path, skip=0):
105105
for i,p in enumerate(path2keys(path)):
106106
sp.append(p)
107107
if i<skip: continue
108-
pcfg({}, keys2path(*sp))
108+
pcfg({}, keys2path(*sp), method='put')
109109

110110
# %% ../nbs/00_core.ipynb 28
111111
automation_path = '/apps/tls/automation'
@@ -169,26 +169,20 @@ def add_route(route):
169169
# %% ../nbs/00_core.ipynb 42
170170
def del_id(id):
171171
"Delete route for `id` (e.g. a host)"
172-
xdelete(get_id(id))
172+
while has_id(id): xdelete(get_id(id))
173173

174174
# %% ../nbs/00_core.ipynb 44
175-
def add_reverse_proxy(from_host, to_url, st_delay='1m', encode:bool=True):
175+
def add_reverse_proxy(from_host, to_url, st_delay='1m', compress:bool=True):
176176
"Create a reverse proxy handler"
177177
if has_id(from_host): del_id(from_host)
178178
res = []
179-
if encode: res.append({"handler": "encode",
180-
"encodings": {"gzip":{}, "zstd":{}},
181-
"prefer": ["zstd", "gzip"]})
182-
proxy = {"handler": "reverse_proxy",
183-
"upstreams": [{"dial": to_url}]}
179+
if compress:
180+
enc = {"gzip":{"level": 1}, "zstd":{"level": "fastest"}}
181+
res.append({"handler": "encode", "encodings": enc, "prefer": ["zstd", "gzip"]})
182+
proxy = {"handler": "reverse_proxy", "upstreams": [{"dial": to_url}]}
184183
if st_delay: proxy["stream_close_delay"] = st_delay
185184
res.append(proxy)
186-
route = {
187-
"handle": res,
188-
"match": [{"host": [from_host]}],
189-
"@id": from_host,
190-
"terminal": True
191-
}
185+
route = { "handle": res, "match": [{"host": [from_host]}], "@id": from_host, "terminal": True }
192186
add_route(route)
193187

194188
# %% ../nbs/00_core.ipynb 48

0 commit comments

Comments
 (0)