# 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. ## Constructors ### `http.newClient` _constructor_ ```nupp function http.newClient(options: http.Options?): http.Client?, string? ``` #### Arguments | Name | Type | Description | | --- | --- | --- | | `options` | `http.Options?` | | #### Returns | Type | Description | | --- | --- | | `http.Client?` | | | `string?` | | ## Types ### `Body` _record_ ```nupp record http.Body is nupp.io.Reader _client: any _transfer: any _closed: boolean _reading: boolean function _next(self, count: integer, destination: nupp.io.Buffer?, offset: integer): (any?, string?) end function read(self, count: integer): (string?, string?) end function readInto(self, destination: nupp.io.Buffer, offset: integer?, count: integer?): (integer?, string?) end function transferTo(self, destination: nupp.io.Writer): (integer?, string?) end function close(self): (boolean, string?) end @drop function release(self): nil end end ``` #### Methods ##### `read` ```nupp read: function read(self, count: integer): string?, string? ``` ###### Arguments | Name | Type | Description | | --- | --- | --- | | `self` | `any` | | | `count` | `integer` | | ###### Returns | Type | Description | | --- | --- | | `string?` | | | `string?` | | ##### `readInto` ```nupp readInto: function readInto(self, destination: nupp.io.Buffer, offset: integer?, count: integer?): integer?, string? ``` ###### Arguments | Name | Type | Description | | --- | --- | --- | | `self` | `any` | | | `destination` | `nupp.io.Buffer` | | | `offset` | `integer?` | | | `count` | `integer?` | | ###### Returns | Type | Description | | --- | --- | | `integer?` | | | `string?` | | ##### `transferTo` ```nupp transferTo: function transferTo(self, destination: nupp.io.Writer): integer?, string? ``` ###### Arguments | Name | Type | Description | | --- | --- | --- | | `self` | `any` | | | `destination` | `nupp.io.Writer` | | ###### Returns | Type | Description | | --- | --- | | `integer?` | | | `string?` | | ##### `close` ```nupp close: function close(self): boolean, string? ``` ###### Arguments | Name | Type | Description | | --- | --- | --- | | `self` | `any` | | ###### Returns | Type | Description | | --- | --- | | `boolean` | | | `string?` | | ##### `release` ```nupp release: function release(self): nil ``` ###### Arguments | Name | Type | Description | | --- | --- | --- | | `self` | `any` | | ###### Returns | Type | Description | | --- | --- | | `nil` | | ### `Client` _record_ ```nupp 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 ``` #### Methods ##### `send` ```nupp send: function http.Client:send(request: http.Request): http.Response?, string? ``` ###### Arguments | Name | Type | Description | | --- | --- | --- | | `request` | `http.Request` | | ###### Returns | Type | Description | | --- | --- | | `http.Response?` | | | `string?` | | ##### `pending` ```nupp pending: function http.Client:pending(): integer ``` ###### Returns | Type | Description | | --- | --- | | `integer` | | ##### `close` ```nupp close: function http.Client:close(): boolean, string? ``` ###### Returns | Type | Description | | --- | --- | | `boolean` | | | `string?` | | ### `FileBody` _record_ ```nupp record http.FileBody path: string | nupp.io.Path contentType: string? end ``` #### Fields | Name | Type | Description | | --- | --- | --- | | `path` | `string | nupp.io.Path` | | | `contentType` | `string?` | | ### `Options` _record_ ```nupp 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 | Name | Type | Description | | --- | --- | --- | | `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?` | | ### `ReaderBody` _record_ ```nupp record http.ReaderBody reader: nupp.io.Reader length: integer? contentType: string? end ``` #### Fields | Name | Type | Description | | --- | --- | --- | | `reader` | `nupp.io.Reader` | | | `length` | `integer?` | | | `contentType` | `string?` | | ### `Request` _record_ ```nupp record http.Request url: nupp.io.URI method: string? headers: { string: string }? body: http.RequestBody? timeoutMs: integer? stallTimeoutMs: integer? maxBytes: integer? end ``` #### Fields | Name | Type | Description | | --- | --- | --- | | `url` | `nupp.io.URI` | | | `method` | `string?` | | | `headers` | `{string: string}?` | | | `body` | `http.RequestBody?` | | | `timeoutMs` | `integer?` | | | `stallTimeoutMs` | `integer?` | | | `maxBytes` | `integer?` | | ### `RequestBody` _type_ ```nupp type http.RequestBody = string | nupp.io.ByteView | nupp.io.Buffer | http.ReaderBody | http.FileBody ``` ### `Response` _record_ ```nupp record http.Response status: integer version: http.Version url: nupp.io.URI body: owned _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` ```nupp ok: function ok(self): boolean ``` ###### Arguments | Name | Type | Description | | --- | --- | --- | | `self` | `any` | | ###### Returns | Type | Description | | --- | --- | | `boolean` | | ##### `header` ```nupp header: function header(self, name: string): string? ``` ###### Arguments | Name | Type | Description | | --- | --- | --- | | `self` | `any` | | | `name` | `string` | | ###### Returns | Type | Description | | --- | --- | | `string?` | | ##### `getAll` ```nupp getAll: function getAll(self, name: string): {string} ``` ###### Arguments | Name | Type | Description | | --- | --- | --- | | `self` | `any` | | | `name` | `string` | | ###### Returns | Type | Description | | --- | --- | | `{string}` | | ##### `headers` ```nupp headers: function headers(self): {string: string} ``` ###### Arguments | Name | Type | Description | | --- | --- | --- | | `self` | `any` | | ###### Returns | Type | Description | | --- | --- | | `{string: string}` | | ##### `close` ```nupp close: function close(self): boolean, string? ``` ###### Arguments | Name | Type | Description | | --- | --- | --- | | `self` | `any` | | ###### Returns | Type | Description | | --- | --- | | `boolean` | | | `string?` | | #### Fields | Name | Type | Description | | --- | --- | --- | | `status` | `integer` | | | `version` | `http.Version` | | | `url` | `nupp.io.URI` | | | `body` | `owned\` | | ### `Version` _type_ ```nupp type http.Version = "1.0" | "1.1" | "2" ``` ## Functions ### `http.file` _function_ ```nupp function http.file(path: string | nupp.io.Path, contentType: string?): http.FileBody ``` #### Arguments | Name | Type | Description | | --- | --- | --- | | `path` | `string | nupp.io.Path` | | | `contentType` | `string?` | | #### Returns | Type | Description | | --- | --- | | `http.FileBody` | | ### `http.reader` _function_ ```nupp function http.reader(reader: nupp.io.Reader, length: integer?, contentType: string?): http.ReaderBody ``` #### Arguments | Name | Type | Description | | --- | --- | --- | | `reader` | `nupp.io.Reader` | | | `length` | `integer?` | | | `contentType` | `string?` | | #### Returns | Type | Description | | --- | --- | | `http.ReaderBody` | |