# The browser port Medlar listens on `127.0.0.1:17616` (D-006; changeable under Settings, Browser; on and off live). Only programs on this PC can reach it. Code: `crates/core/src/connector/`. ## Format `GET /` answers `{"name": "Medlar", "version": "0.1.0"}`: a ping. `POST /` with `Content-Type: application/json` and a body of one link or a list of them. This is Nacre's `custom_body` as it is (D-003, D-010); unknown fields are ignored. | Field | | | |---|---|---| | `url` | required | http, https, ftp, ftps, ftpes, sftp, rtsp, mms, mmsh, mmst | | `filename` | | made safe: path parts, control characters and leading dots go | | `referrer` | | the page; sent as `Referer`, kept to find a new link later | | `cookies` | | as in a `Cookie` header; kept in the keyring only | | `user_agent` | | sent with the download | | `headers` | | object of name to value; `Cookie`, `User-Agent`, `Referer` fill the fields above when those are empty | | `size`, `mime` | | the sender's guess, shown only | Answer `200 {"accepted": n, "refused": [{"index": i, "why": "scheme"}]}` when one or more links came in, else an error with `{"error": ""}`: | Status | `error` | Why | |---|---|---| | 403 | `host` | `Host` is not `127.0.0.1:` or `localhost:` (DNS rebinding) | | 403 | `origin` | an `Origin` header, `Sec-Fetch-Site` other than `none`, or `Sec-Fetch-Mode: cors` | | 405 | `preflight`, `method` | `OPTIONS`, `Access-Control-Request-Method`, or anything but GET and POST | | 415 | `content-type` | not `application/json` (form types, `text/plain`) | | 404 | `path` | anything but `/` | | 400 | `malformed`, `body` | broken HTTP, or JSON that is no link or list | | 411 | `length` | chunked body | | 413 | `too-large`, `too-many` | head over 16 KiB, body over 1 MiB, list over 1000 links | | 408 | `slow` | request not in within 5 s | | 429 | `busy` | over 30 at once or 5 a second | | 422 | `no-links` | no link in it could be taken (`why`: `missing`, `invalid`, `scheme`) | ## Examples ```sh curl -s http://127.0.0.1:17616/ curl -s -H 'Content-Type: application/json' -d '{"url": "https://example.com/a.zip"}' http://127.0.0.1:17616/ curl -s -H 'Content-Type: application/json' \ -d '[{"url": "https://example.com/a.zip", "filename": "a.zip", "referrer": "https://example.com/", "cookies": "k=v", "user_agent": "UA", "headers": {"X-Kind": "one"}}, {"url": "ftp://example.com/b.iso"}]' \ http://127.0.0.1:17616/ ``` ## Security - Bound to 127.0.0.1 only, never 0.0.0.0. Port 15151 belongs to AB Download Manager and is not used. - No CORS headers in any answer, so a web page can't read one; JSON only, so a page can't post without a preflight, and preflights are refused. `Host` is checked against loopback and the port, so a rebound name is refused. - One request per connection, 5 s to send it, 16 connections at once, a token bucket against floods. - Headers in values with line breaks or control characters are dropped, and so are hop-by-hop and controlled ones (`Connection`, `Host`, `Range`, `Accept-Encoding`, `Transfer-Encoding`, `Content-*`, `If-*`, `Proxy-*`, `Sec-*` …), at most 32 kept. Cookies, a login in the link and secret headers go to the keyring (`secret::Secrets`), never to the store or the log. - Sender log (`Connector::log`): when, what (link without login or query string), accepted or why not, and the sending program's name from `/proc/net/tcp` when it is the user's own. - Links arrive on the channel from `Connector::start` as `Arrival`; `Incoming::task` makes a task and keeps its secret.