6.52. kink/http/REQ¶
6.52.1. type req¶
`req` is an HTTP request.
6.52.1.1. Req.method¶
`method` returns a `str` of the method of the request, like 'GET' or 'POST.
6.52.1.2. Req.uri¶
`uri` returns a `str` of the URI of the request.
6.52.1.3. Req.headers¶
`headers` returns a `map` from header names, to vectors of the corresponding header values.
Keys of the map are `str` values, which are case-insensitive.
Values of the map are `vec` values which contain `str` values.
Example
:REQ.require_from('kink/http/')
:Req <- REQ.new('POST' 'https://example.kink-lang.org/form'){(:C)
C.header('Content-Type' 'text/plain')
C.header('Accept' 'application/octet-stream')
C.header('Accept' '*/*')
}
stdout.print_line(Req.headers.repr)
# Output:
# (flat_map "accept"=>["application/octet-stream" "*/*"] "content-type"=>["text/plain"])
6.52.1.4. Req.content¶
`content` method returns the content of the request as a `req_content` value.
6.52.1.5. Req.redirect_count¶
`redirect_count` returns the number of redirects until `Req`.
If `Req` is made without the redirect source, the result will be 0.
If `Req` is made with a redirect source, the result will be Req.redirect_source.redirect_count + 1.
6.52.1.6. Req.redirect_source¶
`redirect_source` returns the `resp` value of the HTTP response from which the request is redirected.
Precondition
Req.redirect_count must not be 0.
6.52.2. REQ.new(Method Uri ...[$config={}])¶
`new` returns a new `req`, with `Method` as the request method, and `Uri` as the URI of the resource.
Preconditions
`Method` must be a `str` of a [RFC 9110] “token”.
`Method` must not be 'CONNECT'.
`Uri` must be a `str` of an http or https URI [RFC 9110 - 4.2.1, 4.2.2].
$config must take a `request_new_config` as a config value.
6.52.3. type request_new_config¶
`request_new_config` is a config value of REQ.new.
6.52.3.1. C.header(Name Val)¶
`header` specifies an HTTP header. This method can be called multiple times to specify multiple header entries.
Preconditions
`Name` must be a `str` of a “token” defined in [RFC 9110].
`Val` must be a `str` which matches /|[\x21-\x7e\x80-\xff]([\t\x20-\x7e\x80-\xff]*[\x21-\x7e\x80-\xff])?/. This assumes that a “field-value” defined in [RFC 9110] is decoded by ISO-8859-1 charset.
6.52.3.2. C.content(Content)¶
`content` specifies that the HTTP request has `Content` as the request content.
If `content` is not called, the request content will be empty.
Precondition
`Content` must be a `req_content`.
6.52.3.3. C.redirect_source(Resp)¶
`redirect_source` specifies that the request is will be performed as a redirect from the previous HTTP response `Resp`.
Precondition
`Resp` must be a `resp`.
6.52.4. REQ.is?(Val)¶
`is?` returns whether `Val` is a `req`.