S065: custom download managers by name and port (D-050), D-022 JSON on 127.0.0.1:<port>, smoke case
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
parent
8386b32064
commit
e258b5b120
1 changed files with 310 additions and 38 deletions
|
|
@ -393,3 +393,49 @@ See `docs/FEATURES.md`; every row names the file that implements it and its revi
|
|||
to `Hub::blocked` (reset in the `load-changed` Started handler). Limits: depends on WebKit's console wording;
|
||||
WebKit may not log blocks for every load type (checked: script, image, fetch, module, async/defer, dynamic import);
|
||||
a block logged just after a new page starts may count for the new page.
|
||||
|
||||
## Custom download manager (D-022, D-050, S065)
|
||||
|
||||
Settings → Downloads → Download managers → "Add your own": a name and a port (1–65535, one entry per port).
|
||||
Stored as `downloads.custom_managers` (`[{name, port, enabled}]`); chosen in "New downloads go to" as
|
||||
`downloads.manager = "custom:<port>"`. Loopback only: the endpoint is always `http://127.0.0.1:<port>/` (no host
|
||||
field), so cookies never leave the machine and the VPN is never used (`net/dlm.rs`, `fetch::local_agent`).
|
||||
|
||||
- **Status ping**: `GET /`; any 2xx = "Found · port N", anything else = "Not running".
|
||||
- **Hand-over**: `POST /` with `Content-Type: application/json`; any 2xx = taken (the download shows as
|
||||
"Sent to <name>"); any other answer or no answer = Nacre downloads the file itself and the toast says why.
|
||||
|
||||
```http
|
||||
POST / HTTP/1.1
|
||||
Host: 127.0.0.1:8123
|
||||
Content-Type: application/json
|
||||
|
||||
{"url": "https://example.com/file.zip", "filename": "file.zip", "referrer": "https://example.com/",
|
||||
"cookies": "session=abc", "user_agent": "Mozilla/5.0 …",
|
||||
"headers": {"Cookie": "session=abc", "User-Agent": "Mozilla/5.0 …", "Referer": "https://example.com/"},
|
||||
"size": null, "mime": null}
|
||||
```
|
||||
|
||||
`cookies` is the Cookie header Nacre would send for that URL (empty when none); `headers` holds only the ones that
|
||||
are set; `size` and `mime` are null (not known before the download starts). A minimal receiver:
|
||||
|
||||
```python
|
||||
#!/usr/bin/env python3
|
||||
# Receives Nacre's downloads on 127.0.0.1:8123 and fetches them with curl.
|
||||
import json, subprocess
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
def do_GET(self): # Nacre's status ping
|
||||
self.send_response(200); self.end_headers()
|
||||
|
||||
def do_POST(self): # a download handed over
|
||||
item = json.loads(self.rfile.read(int(self.headers["Content-Length"])))
|
||||
args = ["curl", "-L", "-o", item["filename"] or "download", item["url"]]
|
||||
for name, value in item["headers"].items():
|
||||
args += ["-H", f"{name}: {value}"]
|
||||
subprocess.Popen(args)
|
||||
self.send_response(200); self.end_headers()
|
||||
|
||||
HTTPServer(("127.0.0.1", 8123), Handler).serve_forever()
|
||||
```
|
||||
|
|
|
|||
Loading…
Reference in a new issue