Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf772ad0

Browse files
committed
Add encoding & stream_close_delay options to add_reverse_proxy
1 parenta8e4c4d commitf772ad0

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

‎fastcaddy/core.py‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,19 @@ def del_id(id):
172172
xdelete(get_id(id))
173173

174174
# %% ../nbs/00_core.ipynb 44
175-
defadd_reverse_proxy(from_host,to_url):
175+
defadd_reverse_proxy(from_host,to_url,st_delay='1m',encode:bool=True):
176176
"Create a reverse proxy handler"
177177
ifhas_id(from_host):del_id(from_host)
178+
res= []
179+
ifencode:res.append({"handler":"encode",
180+
"encodings": {"gzip":{},"zstd":{}},
181+
"prefer": ["zstd","gzip"]})
182+
proxy= {"handler":"reverse_proxy",
183+
"upstreams": [{"dial":to_url}]}
184+
ifst_delay:proxy["stream_close_delay"]=st_delay
185+
res.append(proxy)
178186
route= {
179-
"handle": [{"handler":"reverse_proxy",
180-
"upstreams": [{"dial":to_url}] }],
187+
"handle":res,
181188
"match": [{"host": [from_host]}],
182189
"@id":from_host,
183190
"terminal":True
@@ -202,16 +209,25 @@ def add_sub_reverse_proxy(
202209
domain,
203210
subdomain,
204211
port:str|int|Sequence,# A single port or list of ports
205-
host='localhost'
212+
host='localhost',
213+
st_delay='1m',
214+
encode:bool=True
206215
):
207216
"Add a reverse proxy to a wildcard subdomain supporting multiple ports"
208217
wildcard_id=f"wildcard-{domain}"
209218
route_id=f"{subdomain}.{domain}"
210219
ifisinstance(port, (int,str)):port= [port]
211220
upstreams= [{"dial":f"{host}:{p}"}forpinport]
221+
res= []
222+
ifencode:res.append({"handler":"encode",
223+
"encodings": {"gzip":{},"zstd":{}},
224+
"prefer": ["zstd","gzip"]})
225+
proxy= {"handler":"reverse_proxy","upstreams":upstreams}
226+
ifst_delay:proxy["stream_close_delay"]=st_delay
227+
res.append(proxy)
212228
new_route= {
213229
"@id":route_id,
214230
"match": [{"host": [route_id]}],
215-
"handle":[{"handler":"reverse_proxy","upstreams":upstreams }]
231+
"handle":res
216232
}
217233
pid([new_route],f"{wildcard_id}/handle/0/routes/...")

‎nbs/00_core.ipynb‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -568,12 +568,19 @@
568568
"outputs": [],
569569
"source": [
570570
"#| export\n",
571-
"def add_reverse_proxy(from_host, to_url):\n",
571+
"def add_reverse_proxy(from_host, to_url, st_delay='1m', encode:bool=True):\n",
572572
"\"Create a reverse proxy handler\"\n",
573573
" if has_id(from_host): del_id(from_host)\n",
574+
" res = []\n",
575+
" if encode: res.append({\"handler\":\"encode\",\n",
576+
"\"encodings\": {\"gzip\":{},\"zstd\":{}},\n",
577+
"\"prefer\": [\"zstd\",\"gzip\"]})\n",
578+
" proxy = {\"handler\":\"reverse_proxy\",\n",
579+
"\"upstreams\": [{\"dial\": to_url}]}\n",
580+
" if st_delay: proxy[\"stream_close_delay\"] = st_delay\n",
581+
" res.append(proxy)\n",
574582
" route = {\n",
575-
"\"handle\": [{\"handler\":\"reverse_proxy\",\n",
576-
"\"upstreams\": [{\"dial\": to_url}] }],\n",
583+
"\"handle\": res,\n",
577584
"\"match\": [{\"host\": [from_host]}],\n",
578585
"\"@id\": from_host,\n",
579586
"\"terminal\": True\n",
@@ -648,17 +655,26 @@
648655
" domain,\n",
649656
" subdomain,\n",
650657
" port:str|int|Sequence, # A single port or list of ports\n",
651-
" host='localhost'\n",
658+
" host='localhost',\n",
659+
" st_delay='1m',\n",
660+
" encode:bool=True\n",
652661
" ):\n",
653662
"\"Add a reverse proxy to a wildcard subdomain supporting multiple ports\"\n",
654663
" wildcard_id = f\"wildcard-{domain}\"\n",
655664
" route_id = f\"{subdomain}.{domain}\"\n",
656665
" if isinstance(port, (int,str)): port = [port]\n",
657666
" upstreams = [{\"dial\": f\"{host}:{p}\"} for p in port]\n",
667+
" res = []\n",
668+
" if encode: res.append({\"handler\":\"encode\",\n",
669+
"\"encodings\": {\"gzip\":{},\"zstd\":{}},\n",
670+
"\"prefer\": [\"zstd\",\"gzip\"]})\n",
671+
" proxy = {\"handler\":\"reverse_proxy\",\"upstreams\": upstreams}\n",
672+
" if st_delay: proxy[\"stream_close_delay\"] = st_delay\n",
673+
" res.append(proxy)\n",
658674
" new_route = {\n",
659675
"\"@id\": route_id,\n",
660676
"\"match\": [{\"host\": [route_id]}],\n",
661-
"\"handle\":[{\"handler\":\"reverse_proxy\",\"upstreams\": upstreams }]\n",
677+
"\"handle\":res\n",
662678
" }\n",
663679
" pid([new_route], f\"{wildcard_id}/handle/0/routes/...\")"
664680
]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp