Repository navigation
Saved examples, proxy authentication, data-driven runs, script requests, streaming - #5
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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.responseentries are edited in place, and unknown fields are kept..example.yamlfile, 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.1includes them.Proxy authentication
--proxy-useronsendandrun.proxy-credentials.json, DPAPI-encrypted on Windows and never in the workspace.HTTPS_PROXY.Data-driven runs
run -d <file>takes a CSV file or a JSON array;-n <count>sets the number of iterations, as in Newman.pm.iterationData(tr.iteration_data, …), and{{name}}works in requests.iterationsand each result'siteration.Requests that scripts send
pm.sendRequest,tr.send_request,tr.SendRequestand$tr.SendRequestgo through TermRest, with the workspace's:Streaming responses (server-sent events, JSON lines)
send: prints the stream as it arrives. The first Ctrl+C stops it and keeps it; a reader that quits (| head) stops it too.Review fixes
Every fix has a test that was checked to fail without it.
Round 1 (17 findings):
HTTPS_PROXYoverrode--proxy-userand the saved sign-in.| headwent unnoticed.event:field did not give the typemessage.{{passphrase}}was not resolved for script requests.Round 2:
Resources (Windows x64, Native AOT,
samplesworkspace)cf4925a)send, small JSON (peak)send, 23.8 MiB body with-o(peak)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:
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
sendRequestwere smoke-tested with the AOT executable.