Module: nupp.io.http

An optional asynchronous HTTP client whose sockets and TLS run in the native Reqwest/Tokio provider. Calls suspend through nupp.suspension: a CLI blocks on the provider's condvar, while a scheduler or SDL host only drives the nonblocking source.

Response bodies and generic request readers are progressive and bounded. A response status is an answer (including 4xx and 5xx); transport and body failures are returned as reasons.

Module contents

Constructors

ConstructorDescription
newClient

Types

TypeKindDescription
Bodyrecord
Clientrecord
FileBodyrecord
Optionsrecord
ReaderBodyrecord
Requestrecord
RequestBodytype
Responserecord
Versiontype

Functions

FunctionKindDescription
Client:closemethod
Client:pendingmethod
Client:sendmethod
filefunction
readerfunction

Constructors#

http.newClientconstructor#

function http.newClient(options: http.Options?): http.Client?, string?

Arguments

NameTypeDescription
optionshttp.Options?

Returns

TypeDescription
http.Client?
string?

Types#

Bodyrecord#

record http.Body is nupp.Reader
    _client: any
    _transfer: any
    _closed: boolean
    _reading: boolean

    function _next(self, count: integer, destination: nupp.Buffer?, offset: integer): (any?, string?)
    end

    function read(self, count: integer): (string?, string?)
    end

    function readInto(self, destination: nupp.Buffer, offset: integer?, count: integer?): (integer?, string?)
    end

    function transferTo(self, destination: nupp.Writer): (integer?, string?)
    end

    function close(self): (boolean, string?)
    end

    @drop
    function release(self): nil
    end
end

Methods

read
read: function read(self, count: integer): string?, string?
Arguments
NameTypeDescription
selfany
countinteger
Returns
TypeDescription
string?
string?
readInto
readInto: function readInto(self, destination: nupp.Buffer, offset: integer?, count: integer?): integer?, string?
Arguments
NameTypeDescription
selfany
destinationnupp.Buffer
offsetinteger?
countinteger?
Returns
TypeDescription
integer?
string?
transferTo
transferTo: function transferTo(self, destination: nupp.Writer): integer?, string?
Arguments
NameTypeDescription
selfany
destinationnupp.Writer
Returns
TypeDescription
integer?
string?
close
close: function close(self): boolean, string?
Arguments
NameTypeDescription
selfany
Returns
TypeDescription
boolean
string?
release
release: function release(self): nil
Arguments
NameTypeDescription
selfany
Returns
TypeDescription
nil

Clientrecord#

record http.Client
    _native: any
    _options: any
    _source: suspension.Source?
    _sourceUsers: integer
    _closed: boolean

    function _retainSource(self, context: suspension.Context): nil
    end

    function _releaseSource(self): nil
    end
end

FileBodyrecord#

record http.FileBody
    path: string | nupp.Path
    contentType: string?
end

Fields

NameTypeDescription
pathstring | nupp.Path
contentTypestring?

Optionsrecord#

record http.Options
    userAgent: string?
    headers: {
        string: string
    }?
    timeoutMs: integer?
    connectTimeoutMs: integer?
    stallTimeoutMs: integer?
    maxRedirects: integer?
    maxPendingRequests: integer?
    maxConnections: integer?
    maxConnectionsPerHost: integer?
    maxBytes: integer?
    compressed: boolean?
    insecureHosts: {string}?
    proxy: string?
    noProxy: string?
    proxyCredentials: string?
end

Fields

NameTypeDescription
userAgentstring?
headers{string: string}?
timeoutMsinteger?
connectTimeoutMsinteger?
stallTimeoutMsinteger?
maxRedirectsinteger?
maxPendingRequestsinteger?
maxConnectionsinteger?
maxConnectionsPerHostinteger?
maxBytesinteger?
compressedboolean?
insecureHosts{string}?
proxystring?
noProxystring?
proxyCredentialsstring?

ReaderBodyrecord#

record http.ReaderBody
    reader: nupp.Reader
    length: integer?
    contentType: string?
end

Fields

NameTypeDescription
readernupp.Reader
lengthinteger?
contentTypestring?

Requestrecord#

record http.Request
    url: nupp.URI
    method: string?
    headers: {
        string: string
    }?
    body: http.RequestBody?
    timeoutMs: integer?
    stallTimeoutMs: integer?
    maxBytes: integer?
end

Fields

NameTypeDescription
urlnupp.URI
methodstring?
headers{string: string}?
bodyhttp.RequestBody?
timeoutMsinteger?
stallTimeoutMsinteger?
maxBytesinteger?

RequestBodytype#

type http.RequestBody = string | nupp.ByteView | nupp.Buffer | http.ReaderBody | http.FileBody

Responserecord#

record http.Response
    status: integer
    version: http.Version
    url: nupp.URI
    body: owned<http.Body>
    _packed: string
    _values: {[string]: {string}}?
    _headers: {
        string: string
    }?
    _closed: boolean

    function _decode(self): nil
    end

    function ok(self): boolean
    end

    function header(self, name: string): string?
    end

    function getAll(self, name: string): {string}
    end

    function headers(self): {
        string: string
    }
    end

    @drop
    function close(self): (boolean, string?)
    end
end

Methods

ok
ok: function ok(self): boolean
Arguments
NameTypeDescription
selfany
Returns
TypeDescription
boolean
header
header: function header(self, name: string): string?
Arguments
NameTypeDescription
selfany
namestring
Returns
TypeDescription
string?
getAll
getAll: function getAll(self, name: string): {string}
Arguments
NameTypeDescription
selfany
namestring
Returns
TypeDescription
{string}
headers
headers: function headers(self): {string: string}
Arguments
NameTypeDescription
selfany
Returns
TypeDescription
{string: string}
close
close: function close(self): boolean, string?
Arguments
NameTypeDescription
selfany
Returns
TypeDescription
boolean
string?

Fields

NameTypeDescription
statusinteger
versionhttp.Version
urlnupp.URI
bodyowned<http.Body>

Versiontype#

type http.Version = "1.0" | "1.1" | "2"

Functions#

http.Client:closemethod#

function http.Client:close(): boolean, string?

Returns

TypeDescription
boolean
string?

http.Client:pendingmethod#

function http.Client:pending(): integer

Returns

TypeDescription
integer

http.Client:sendmethod#

function http.Client:send(request: http.Request): http.Response?, string?

Arguments

NameTypeDescription
requesthttp.Request

Returns

TypeDescription
http.Response?
string?

http.filefunction#

function http.file(path: string | nupp.Path, contentType: string?): http.FileBody

Arguments

NameTypeDescription
pathstring | nupp.Path
contentTypestring?

Returns

TypeDescription
http.FileBody

http.readerfunction#

function http.reader(reader: nupp.Reader, length: integer?, contentType: string?): http.ReaderBody

Arguments

NameTypeDescription
readernupp.Reader
lengthinteger?
contentTypestring?

Returns

TypeDescription
http.ReaderBody