http.bend checks
raw source on the hub · import cswap-bend-cli@0.1.0.0/http.bend as Http
1 import
import Base
Types
type Reply source · line 153 · raw
Data
status, the raw header block (one line each, \n ended), the body.
Reply@status:U32 -> @head:String -> @body:String -> Reply
Definitions
def quote.pick source · line 7 · raw
@esc:Bool -> @c:Char -> @rest:String -> String
def quote.char source · line 14 · raw
@+c:Char -> @rest:String -> String
def quote source · line 18 · raw
@s:String -> String
The body of a quoted curl config value: \ and " escaped.
def line source · line 25 · raw
@key:String -> @value:String -> String
def header.line source · line 28 · raw
@kv:Pair(String, String) -> String
def headers source · line 32 · raw
@hs:List<&1, Pair(String, String)> -> String
def body.pick source · line 39 · raw
@empty:Bool -> @body:String -> String
def body.line source · line 46 · raw
@+body:String -> String
def config source · line 52 · raw
@method:String -> @url:String -> @hs:List<&1, Pair(String, String)> -> @body:String -> @timeout_s:U32 -> String
curl config for one request. dump-header = - puts the response headers on
stdout ahead of the body; write-out appends the HTTP status as the last
line. An empty body sends no data line (a GET stays a GET).
def header.pick source · line 63 · raw
@hit:Bool -> @+name:String -> @+line:String -> Maybe<&2, String>
Header lookup, case-insensitive on the name. name must be lowercase and
end with :.
def header.match source · line 70 · raw
@+name:String -> @+line:String -> Maybe<&2, String>
def header.find source · line 73 · raw
@+name:String -> @ls:List<&2, String> -> @found:Maybe<&2, String> -> Maybe<&2, String>
def header source · line 82 · raw
@+name:String -> @raw:String -> Maybe<&2, String>
def run source · line 87 · raw
@cfg:String -> @timeout_ms:U32 -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Pair(String, String))>)
Run one request: answers curl's exit status and (stdout, stderr). stdout is the response headers, the body, then the HTTP status on the last line.
def after_headers.pick source · line 92 · raw
@blank:Bool -> @rest:List<&2, String> -> @deeper:List<&2, String> -> List<&2, String>
def after_headers source · line 100 · raw
@ls:List<&2, String> -> List<&2, String>
Lines after the header block (the first blank line).
def last_line.pick source · line 107 · raw
@m:Maybe<&2, String> -> String
def status source · line 115 · raw
@raw:String -> U32
The HTTP status config asked curl to append as the last line; 0 when absent.
def body.of source · line 118 · raw
@+ls:List<&2, String> -> String
def body source · line 122 · raw
@raw:String -> String
The body: what lies between the headers and the status line.
def rewrite.pick source · line 127 · raw
@live:Bool -> @base:String -> @+url:String -> String
def rewrite source · line 136 · raw
@+base:String -> @+url:String -> String
With CSWAP_TEST_HTTP_BASE set (base non-empty), https://host/path goes to
base/host/path: plain http, same headers and body (contract section 5).
def base.pick source · line 139 · raw
@r:Result<&1, &1, Pair(U32, String), String> -> String
def test_base source · line 147 · raw
IO(String)
The test base URL, or "" when unset.
def head.pick source · line 156 · raw
@blank:Bool -> @h:String -> @rest:String -> String
def head.of source · line 164 · raw
@ls:List<&2, String> -> String
The header lines: everything before the first blank line.
def reply.ok source · line 171 · raw
@+out:String -> Result<&2, &2, String, Reply>
def reply.exit source · line 175 · raw
@ok:Bool -> @timed_out:Bool -> @out:String -> Result<&2, &2, String, Reply>
curl exit 28 is its own timeout; anything else that fails is the network.
def reply.of2 source · line 184 · raw
@+st:U32 -> @oe:Pair(String, String) -> Result<&2, &2, String, Reply>
def reply.of source · line 188 · raw
@r:Pair(U32, Pair(String, String)) -> Result<&2, &2, String, Reply>
def reply source · line 192 · raw
@r:Result<&1, &1, Pair(U32, String), Pair(U32, Pair(String, String))> -> Result<&2, &2, String, Reply>
def request source · line 202 · raw
@method:String -> @url:String -> @hs:List<&1, Pair(String, String)> -> @body:String -> @+timeout_s:U32 -> IO(Result<&2, &2, String, Reply>)
One request through curl (config on stdin, so the token never reaches argv),
with the test seam applied. Fail carries the error kind: timeout or
network.