Skip to content

Saved examples, proxy authentication, data-driven runs, script requests, streaming - #5

Merged
ShikeChen-MS merged 11 commits into
mainfrom
examples-proxy-runs-streaming
Nov 18, 2026
Merged

ShikeChen-MS merged 11 commits into
mainfrom
examples-proxy-runs-streaming

Conversation

@ShikeChen-MS

Copy link
Copy Markdown
Owner

Five roadmap items, two review→fix rounds, and a resource check against TermRest's goal: about 80% of what Postman and Insomnia do, with about 20% of the resources.

Features

Saved examples (Postman's saved responses), editable

  • Listed under their request in the tree (e.g. <name>). Opening one shows its request in the editor, without Send, and its response in an editor in the response pane's place: status and reason, body language, body (with Beautify for JSON) and headers.
  • Save as example, on the response's status line or in the Request menu, saves any response. One opened from the history goes to the request it was sent from.
  • Rename, duplicate and delete them from the tree.
  • v2.1: the item's response entries are edited in place, and unknown fields are kept.
  • v3: each example is its own .example.yaml file, read only when its request is first expanded or opened. Saves rewrite only the changed lines; renames and deletes are applied to the files. convert --to v2.1 includes them.

Proxy authentication

  • A 407 is answered with Basic, Digest, NTLM or Negotiate, as the proxy asks.
  • The sign-in comes from one of these, in order of precedence:
    • --proxy-user on send and run.
    • Tools › Settings › Proxy sign-in, kept in the user's private proxy-credentials.json, DPAPI-encrypted on Windows and never in the workspace.
    • The proxy URL, or HTTPS_PROXY.
  • Without any, NTLM and Negotiate proxies get the user's own sign-in. A proxy URL set in the workspace must first be approved for that folder.

Data-driven runs

  • run -d <file> takes a CSV file or a JSON array; -n <count> sets the number of iterations, as in Newman.
  • Scripts read the row through pm.iterationData (tr.iteration_data, …), and {{name}} works in requests.
  • The file is checked before anything is sent, then read one row at a time. The report has iterations and each result's iteration.

Requests that scripts send

  • pm.sendRequest, tr.send_request, tr.SendRequest and $tr.SendRequest go through TermRest, with the workspace's:
    • client certificates and CA bundle;
    • proxy and its sign-in;
    • limits and cookies.
  • Each is recorded to HAR and logged as one line in the script output. JavaScript runs up to 6 at once; the other languages one at a time.

Streaming responses (server-sent events, JSON lines)

  • UI: shows the stream as it arrives (the last 64 KB, at most four updates a second). Esc or Stop ends it and keeps what arrived as the response. Server-sent events get an Events tab; events are stored as offsets and read lazily.
  • send: prints the stream as it arrives. The first Ctrl+C stops it and keeps it; a reader that quits (| head) stops it too.
  • Decoded as it arrives (gzip, deflate including raw deflate, br). The maximum response size still applies.

Review fixes

Every fix has a test that was checked to fail without it.

Round 1 (17 findings):

  • Data-file values named like secrets were not redacted.
  • A duplicate name in a JSON data row stopped the run mid-way.
  • DPAPI refused an empty password.
  • A masked proxy password was lost when the proxy changed.
  • A user and password in HTTPS_PROXY overrode --proxy-user and the saved sign-in.
  • After a stream's body was read, Esc, Stop and Ctrl+C did nothing while its scripts ran.
  • UTF-8 streamed to a Windows console was garbled.
  • | head went unnoticed.
  • Opening another request left a stream running.
  • Raw-deflate streams failed to decode.
  • An empty event: field did not give the type message.
  • A certificate's {{passphrase}} was not resolved for script requests.
  • A cancelled answer could leave a partial line in the script worker.
  • v3 examples:
    • a rename followed by a failed write left a duplicate;
    • examples were lost under a deleted request file;
    • a duplicated example lost its place after a reload.

Round 2:

  • Settings sign-in: saving Settings in one window could delete or garble a proxy sign-in another TermRest had saved meanwhile. The dialog now shows the file as it is, and applies the sign-in only when it was edited or moved to another proxy.

Resources (Windows x64, Native AOT, samples workspace)

before (cf4925a) this PR
Binary 20.73 MiB 21.06 MiB
UI idle, working set 86.9 MiB 31.5 MiB
UI idle, private 72.0 MiB 16.5 MiB
UI idle CPU per 10 s 0–60 ms 0–60 ms
send, small JSON (peak) 23.0 MiB 23.6 MiB
send, 23.8 MiB body with -o (peak) 48.3 MiB 49.8 MiB

The examples feature first added about 12 MiB to idle memory. Measuring showed the live managed heap is only about 12 MiB; most idle memory was startup garbage that the GC kept until its next collection. Two changes fixed it:

  • The example editor is now created when the first example is opened.
  • The UI runs one compacting collection that returns memory to the OS once it goes idle (GCCollectionMode.Aggressive), only after 8 MB or more of new allocations.

Startup and idle CPU are unchanged within noise. The README's numbers are updated.

Testing

  • Windows: Core 843 passed (6 skipped: Unix-only or opt-in), CLI 43 (3 skipped), UI 300.
  • WSL Ubuntu 24.04: the CLI suite (the Unix pipe and Ctrl+C stream tests ran there) and the Core classes the fixes touched.
  • AOT: the win-x64 publish has no warnings. SSE and a script's sendRequest were smoke-tested with the AOT executable.

ShikeChen-MS and others added 11 commits November 17, 2026 21:37
The README's opening says what TermRest is, and isn't: not another Postman, but a small client for the 80% of an API client that people use every day, with about 20% of the resources, so that memory and CPU go back to the user's own work. It gives the measured numbers (one executable of about 21 MB; the UI under 90 MB with a workspace open and next to no CPU when idle; about 23 MB for a send), says what it doesn't run (no account, cloud sync, telemetry, update checks or background service; script runtimes only while scripts need them), and what it leaves to Postman and Newman, which open the same files.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Saved examples (Postman's saved responses) are shown, edited and saved from responses. In the tree they are listed under their request (e.g. <name>). Save as example, on the response's status line or in the Request menu, saves the response shown as an example of its request: its status, its headers as the server sent them, its body as text (a binary body is left out, and a body over 1 MB asks first), and the request as the editor has it; a response opened from the history goes to the request it was sent from. Opening an example edits its request (method, URL, parameters, headers and body) in the request editor, without Send, and its response (status code and reason, the body's language, with Beautify for JSON, body and headers) in the response pane's place; an edit writes only what was edited, and a body too long for the editor is shown read-only and kept as it is. Examples are renamed, duplicated and deleted from the tree. In a v2.1 collection they are the item's response entries, edited in place (the rest of each, its id and cookies, stays). In a v3 collection each is an .example.yaml file, read only when its request is first expanded or opened, or the collection is converted or copied, so a collection with many examples opens as fast as one without: an edit rewrites the changed lines of its file, a new example gets a file named for it (a name its file can't have kept in it, as Postman keeps it) and its request an examples key if it had none, a renamed one is renamed (also in case only), a deleted one deleted, and a file that can't be read is left alone and named in Workspace info. convert --to v2.1 includes v3 examples. A request's file is no longer compared with its examples when saving.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
A proxy that asks for a user name and password (407 Proxy Authentication Required) gets the ones given for it, answered with Basic, Digest, NTLM or Negotiate as it asks: those typed in Tools › Settings › Proxy sign-in, given with send and run's new --proxy-user (user:password, or user to type the password unseen; DOMAIN\user for NTLM), or in the proxy's URL (http://user:password@host:port, also in HTTPS_PROXY), in that order. Proxy sign-in keeps them for the proxy the settings name (or the system's) in proxy-credentials.json in the user's configuration folder, never in the workspace, which comes with its repository: the file is readable by the user only (mode 600 on Unix), and on Windows its passwords are also encrypted for the user's account with DPAPI (through P/Invoke, as Native AOT has no ProtectedData); a password left masked stays, and clearing the user name forgets them. Without any, a proxy that asks for NTLM or Negotiate, as corporate proxies do, gets the user's own sign-in, as browsers give it; .NET sends it to no Basic or Digest proxy. A 407 that comes back (or a tunnel refused with one) says how to give a sign-in. --proxy (-x) sets the proxy of send and run in place of the workspace's (a URL, host:port as curl takes it, system or none), with no approval needed as the user typed it. OAuth 2.0 token requests sign in to the proxy too. The settings dialog keeps fitting a terminal of 30 rows. The README's roadmap no longer lists saved examples and proxy authentication.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
termrest run -d <file> (--iteration-data, as in Newman) runs the requests once for each row of a data file, each run an iteration: CSV with a header row that names the values (RFC 4180: values with commas, quotes or line breaks in double quotes, "" for a quote; lines without values skipped), or JSON, an array of objects. A row's values are data variables: {{name}} in requests, below this request's variables (--var) and above the environment's, as in Postman, and in scripts pm.iterationData, tr.iteration_data, tr.IterationData and $tr.IterationData (JavaScript and Python get the JSON values with their types), with the iteration in pm.info.iteration and iterationCount (tr.info.iteration and iteration_count, tr.Info.Iteration and IterationCount); pm.variables and the other languages' variables read the data scope in its place, and the legacy data and iteration globals are the row and the iteration. -n (--iteration-count) runs that many iterations, with or without data; past a data file's last row, that row is used again. The file is read through once before anything is sent, so that a row that isn't valid stops the run at once (exit code 2), then one row at a time, so a large file takes no more memory than a row. Output says which iteration runs, and the JSON report has the number of iterations and the iteration of each result.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
pm.sendRequest no longer uses the runtime's own fetch, and Python, C# and PowerShell scripts get the same: tr.send_request(request, **fields), tr.SendRequest(request) and SendRequestAsync, and $tr.SendRequest(request). A request goes out as TermRest's own do: with the workspace's client certificates (matched by URL), CA bundle and SSL verification, proxy and its sign-in, timeout, redirects and response size limit, and the session's cookies; it may fetch an OAuth 2.0 token. It takes a URL, or a request as Postman's pm.sendRequest takes it (url, method, header, body, auth), and what the other languages write naturally: headers as a map or pairs, form fields as a map, a body as text or any other JSON (sent as JSON). As in Postman, {{variables}} are sent as written (a new VariableResolver.Literal), with a hint naming the language's replaceIn when some are; the auth is the request's own, none inherited. Scripts get the response as tr.response has it, or the error (ConnectionError in Python, HttpRequestException in C# and PowerShell), and a line in their output, without the URL's query: POST https://host/login → 200 OK (85 ms). Requests are recorded while recording, not kept in the history.

The protocol: the worker writes {"send":{"id":n,"request":…}} (after its reply marker), and ScriptWorker starts the request while it goes on reading; the answer, {"sent":{"id":n,…}}, is a line of the worker's input, written under a lock. JavaScript resolves it as it comes in (several at a time; six are sent at once at most); Python, C# and PowerShell send one at a time and read their answer themselves, and a request started after the scripts ended is refused, so no answer is ever read as the next message. Requests still running when the scripts reply are cancelled once the answer being written is whole, and none is answered after the reply; when the runtime is stopped (time limit, cancel), they are cancelled at once.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
A response of server-sent events (text/event-stream) or JSON lines (application/x-ndjson, ndjson, jsonl, x-jsonlines, json-seq, stream+json) is read as it arrives, part by part, decoded on the way (gzip, deflate, br; a counting stream keeps the size received), within the maximum response size. A watcher set on the prepared request (IStreamWatcher) gets its head and each part, and can stop it: what arrived is then the response, as a whole one would be (ResponseSnapshot.Stopped, with a warning), so its post-response scripts run on it and it goes to the history and the recording. A request timeout that ends a stream keeps it the same way, and so does a connection that ends before the stream does; cancelling the request still discards it.

The full-screen UI shows a stream while it arrives, four times a second at most and only when more came: its status, its headers, and the end of its body (a LiveResponse keeps the last 64 KB, not the stream). Esc, or Stop (the Send button meanwhile), ends it keeping what arrived. Once it ends, server-sent events get an Events tab, one row per event (type, id, the start of its data; Enter shows its data in full, JSON pretty-printed, to copy), read as the HTML standard reads them. An event keeps only where it is in the body (its id too), and the table reads its cells when they are drawn, so a long stream's events take little memory; a large body's events are read in the background.

send prints a stream to standard output as it arrives (after its headers with -i), unless -o or --filter take it whole; the first Ctrl+C stops it, keeping what arrived, through a hook in TermRest's own signal handling (CliApp.Interrupt), and a second one cancels as before. run reads streams whole.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Data runs and proxies: a data file's values named like secrets (apiToken) are redacted in recordings and reports as variables are; a JSON data file with a name twice in one object is refused when it is read, before the run, rather than failing in the middle of it. Proxy sign-in: a password left masked in Settings moves with the sign-in when the proxy setting changes in the same save (also from the system's proxy); the credentials file is read again before each save, so sign-ins another TermRest saved meanwhile stay; an empty password is kept without DPAPI, which refused it, and a password that cannot be encrypted is reported rather than crashing the dialog. --proxy-user and the saved sign-in now take precedence over a user and password in HTTPS_PROXY, which .NET preferred.

Streams: once the body is read, Esc, Stop and Ctrl+C cancel the scripts that run on it again (IStreamWatcher.Ended), rather than doing nothing. send writes a stream to a console as text, decoded as UTF-8 across parts, rather than as bytes in the console's code page; to a pipe through its raw handle, so a reader that quits (| head) stops the stream rather than going unnoticed. Opening another request stops a stream still arriving, keeping what arrived. Raw deflate streams are decoded (their first byte tells, as for whole bodies), and an empty event: field leaves the type "message", as browsers have it.

Script requests: a client certificate's {{passphrase}} (and a private_key_jwt signing certificate's) is resolved as for any request, and the request's warnings follow its line in the script output; an answer to the runtime is written whole even when the scripts are cancelled meanwhile. Postman v3 examples: a rename followed by a failed write no longer leaves a duplicate, an example saved for a request whose file was deleted writes the request again, and a copied example stays right after its original after a reload.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The Settings dialog showed the proxy sign-in as TermRest read it when it started, and saving applied it over the credentials file read again, edited or not: a sign-in another TermRest had saved since for the same proxy (the system's, which every workspace without a proxy of its own shares) was deleted, or got this one's user name with its password. The dialog now shows the file as it is when it opens, and saving applies the sign-in only when it was edited, or when the proxy changed while one was shown (it moves to the new proxy, as before); naming a proxy while no sign-in is shown keeps the one kept for that proxy, which was deleted before. A file that cannot be read is not adopted for the session, which keeps its sign-ins.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…used

The full-screen UI kept about 75 MB of private memory while idle, for a managed heap of about 12 MB live: the rest was what starting (reading the workspace, building and drawing the window) left behind, which the GC keeps until its next collection, however long the UI stays idle. UiPace now runs one full, compacting collection that gives memory back (GCCollectionMode.Aggressive) once the UI is idle, a second after it starts and after each time it was in use, when 8 MB or more were allocated since the last one: a few milliseconds while nothing happens. Idle on the samples, the UI takes about 32 MB (working set, Windows x64; about 87 MB before), with no change in CPU at startup or when idle. The editor of an example's response is made when the first example is opened, as most sessions open none: made at startup, it alone added 8 MB to the idle memory. README: the numbers.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
On CI runners, a new test server's first answer (its endpoint is built on the first request) took longer than the 400 ms request timeout, which then ended the request before the stream began: no response, and a NullReferenceException in the test. The test now warms the endpoint with a short stream first, gives the timed request 2 s, and reports the exchange's error if there is no response.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…r listens

The test server listens on 127.0.0.1, and its URLs say localhost, which a Windows runner resolves to ::1 first: Windows takes 2 s to give up on a refused connection, which the test's 2 s request timeout did not leave room for. The timed request (and the one before it, which builds the server's endpoint) now goes to 127.0.0.1.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@ShikeChen-MS
ShikeChen-MS merged commit 3288f9f into main Nov 18, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant