Replies: 2 comments
|
Repurposed this from a simple description helper into full bidirectional cURL support: |
|
Implemented in #320 — both directions from the proposal:
Both directions cover the flag subset from the proposal ( Closing this out — further review happens on the PR. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Overview
Full, bidirectional cURL support — not just a description string. Two new pieces:
CURLTask(String)— parse a cURL command line and execute it directly as a request..cURLDescription()onDataTask/DownloadTask/UploadTask— produce the cURL command line equivalent to a declared request, built with per-property fidelity rather than reconstructed after the fact.Direction 1 —
CURLTask(String).result()@PropertyBuilder/Propertycomposition is meant for compile-time trees, not for building one dynamically from a parsed string at runtime. SoCURLTaskdoesn't route through thePropertygraph at all: it parses the string and constructs aRequestConfigurationdirectly — RequestDL's own module code can freely populate itsinternal(set)properties — then hands it straight toInternals.Session.execute(...), bypassingResolveentirely."Total support" for curl (~250 flags across scripting/protocols/retries/etc.) isn't a realistic or useful target. Scoping the parser to a documented common subset, with everything else explicitly rejected rather than silently ignored:
-X/--request-H/--header(repeatable)-d/--data/--data-raw/--data-binary-F/--form(repeatable)-u/--user(basic auth)--url, plus a bare trailing URL-G/--get(turns-dinto query items)Out of scope for v1: redirect-following flags, cookie jars,
--resolve, HTTP/3, non-http(s)schemes, TLS/proxy flags (-k,--cacert,-x). Shell-quoting rules (the usual\'-escapes and$'...'ANSI-C quoting seen in "copy as cURL" output from browser devtools) need to be handled by the tokenizer, but only for arguments — not full POSIX shell semantics (no variable expansion, no command substitution).Direction 2 —
.cURLDescription()Rather than serializing the already-resolved
RequestConfigurationafter the fact (which loses structure — a multipart body, by the time it's justRequestConfiguration.body, is already flattened into one byte stream with a boundary, so it could only be reproduced as a single--data-binaryblob, not per-field-Fflags), this builds the cURL string during the same graph walk every property already participates in:CURLEncoder(reference type) becomes a new key onRequestEnvironmentValues, same pattern\.loggeralready uses (LoggerEnvironmentKey.swift)..cURLDescription()injects a fresh encoder via the existing.environment(_:_:)modifier mechanism.PropertyNode.make(_ make: inout Make)(BaseURL,Headers,Query,Payload/Form,Authorization, ...) gets a small addition: after doing its real work, checkRequestEnvironmentValues.current.curlEncoderand, if present, append its own fragment —Form's node appends one-F "field=value"per field, before those fields are ever flattened into multipart bytes. This works with zero changes toMake's shape, becauseRequestEnvironmentValues.currentis already a task-local, readable from inside anymake()call today.RawTaskgets a second method alongside.result()that callsResolve(root:environment:).partiallyBuild()— the lighter internal variant that walks the tree and populatesMakewithout constructing a realInternals.Sessionor resolving the system proxy, neither of which is needed just to describe a request. It then reads back the accumulated string from the encoder instead of touching the network.-X, url,-Hs,-Fs/-d) at description time, rather than in graph-visitation order, since@PropertyBuilderdeclaration order isn't necessarily the order flags should print in.This is a cross-cutting addition, not a single new file — every property type that should be curl-representable needs its own small contribution. It can be built incrementally: start with
BaseURL,Headers,Query,Payload,Authorization, extend to others later. TLS/proxy/session-level flags on this direction are deferred the same way as direction 1.Milestone: 4.3.0
All reactions