nupp.io.http.spi

Shared interfaces for HTTP implementations.

The HTTP module selects during initialization. Provider functions have no implicit receiver; Client and Response methods do. Request, Options, Version, and Capabilities come from nupp.io.http.messages, URI from nupp.io.uri, and Body is the canonical nupp.io Reader interface.

A Client owns its transport and outstanding work. A successful send returns an affine Response owning the response resources and body reader. Preserve borrowing of the Request during send and exclusive access during pump. Closing clients and responses must release resources on success, error, and cancellation paths. Implementers must not replace these affine contracts with unowned table aliases.

Capabilities describe actual behavior, including streaming, policy control, and protocol observability. Unsupported options must follow the public HTTP API's error behavior. The facade selects the implementation at require-time; clients and resource methods retain direct provider operations.

Module contents

Types

TypeKindDescription
BodyinterfaceA forward-only byte source.
Clientinterface
Providerinterface
Responseinterface

Types#

Bodyinterface#

interface Body is nupp.Closeable ...

A forward-only byte source.

An interface rather than the concrete things that satisfy it. A buffer's reader, an open file and an HTTP response body are all one of these, so code written against the contract works over any of them without knowing which it has.

Members

NameKindDescription
readmethodReads up to count bytes.
readSpanmethodReads directly into a checked writable span.
readIntomethodReads into a buffer.
transferTomethodWrites everything left to a writer.

readmethod#

read: function(exclusive self: Reader, count: integer): (string?, string?)

Reads up to count bytes.

An empty answer is the end.

Arguments
NameTypeDescription
exclusive selfBody

this reader

countinteger

the most bytes to read

Returns
TypeDescription
string?

the bytes, or nil when the reader is closed

string?

why it could not read, when unsuccessful

Raises
TypeCondition
string

when count is not a positive integer

readSpanmethod#

readSpan: function(exclusive self: Reader, exclusive destination: span.Writable<uint8>): (integer?, string?)

Reads directly into a checked writable span. A zero answer is the end.

Arguments
NameTypeDescription
exclusive selfBody

this reader

exclusive destinationspan.Writable<uint8>

the positive-sized range to fill

Returns
TypeDescription
integer?

how many bytes were read, or nil when the reader is closed

string?

why it could not read, when unsuccessful

readIntomethod#

readInto: function(
    exclusive self: Reader,
    exclusive destination: Buffer,
    offset: integer?,
    count: integer?
): (integer?, string?)

Reads into a buffer.

A zero answer is the end.

Arguments
NameTypeDescription
exclusive selfBody

this reader

exclusive destinationBuffer

the buffer to write into

offsetinteger?

where in the destination to start, or the beginning

countinteger?

the most bytes to read

Returns
TypeDescription
integer?

how many bytes were read, or nil when the reader is closed

string?

why it could not read, when unsuccessful

transferTomethod#

transferTo: function(exclusive self: Reader, exclusive destination: Writer): (integer?, string?)

Writes everything left to a writer.

Arguments
NameTypeDescription
exclusive selfBody

this reader

exclusive destinationWriter

the writer to fill

Returns
TypeDescription
integer?

how many bytes moved, or nil on failure

string?

why it could not, when unsuccessful

Clientinterface#

interface Client is nupp.Closeable ...

Members

NameKindDescription
pumpmethodServices outstanding client work, waiting up to the given milliseconds for some of it to move, while holding...
pendingmethodReturns the number of outstanding requests or transfers.
sendmethodBorrows the Request while sending and returns an owned Response or an error.

pumpmethod#

pump: function(exclusive self: Client, timeoutMs: integer?): nil
@readonly

Services outstanding client work, waiting up to the given milliseconds for some of it to move, while holding exclusive client access.

Arguments
NameTypeDescription
exclusive selfClient
timeoutMsinteger?
Returns
TypeDescription
nil

pendingmethod#

pending: function(self: Client): integer
@readonly

Returns the number of outstanding requests or transfers.

Arguments
NameTypeDescription
selfClient
Returns
TypeDescription
integer

sendmethod#

send: function(self: Client, borrows request: Request): (Response?, Error?)
@readonly

Borrows the Request while sending and returns an owned Response or an error.

Arguments
NameTypeDescription
selfClient
borrows requestRequest
Returns
TypeDescription
Response?
Error?

Providerinterface#

interface Provider ...

Members

NameKindDescription
priorityfield
newClientmethodConstructs an owned client with the requested transport policy.
capabilitiesmethodReports the guarantees this implementation actually provides.

priorityfield#

priority: integer?
@readonly

newClientmethod#

newClient: function(options: Options?): Client
@readonly

Constructs an owned client with the requested transport policy.

Arguments
NameTypeDescription
optionsOptions?
Returns
TypeDescription
Client

capabilitiesmethod#

capabilities: function(): Capabilities
@readonly

Reports the guarantees this implementation actually provides.

Returns
TypeDescription
Capabilities

Responseinterface#

interface Response is nupp.Closeable ...

Members

NameKindDescription
statusfieldHTTP response status code.
versionfieldObserved protocol version, absent when the host cannot expose it.
urlfieldCanonical final response URI, including completed redirects.
bodyfieldOwned response reader whose lifetime is governed by the response.
okmethodReports whether the status is in the successful 2xx range.
headermethodReturns one header value by case-insensitive name, or nil if absent.
headerValuesmethodReturns all values for a case-insensitive header name.
headersmethodReturns a fresh response header mapping keyed by lowercase name.

statusfield#

status: integer
@readonly

HTTP response status code.

versionfield#

version: Version?
@readonly

Observed protocol version, absent when the host cannot expose it.

urlfield#

url: URI
@readonly

Canonical final response URI, including completed redirects.

bodyfield#

body: Body
@readonly

Owned response reader whose lifetime is governed by the response.

okmethod#

ok: function(self: Response): boolean
@readonly

Reports whether the status is in the successful 2xx range.

Arguments
NameTypeDescription
selfResponse
Returns
TypeDescription
boolean

headermethod#

header: function(self: Response, name: string): string?
@readonly

Returns one header value by case-insensitive name, or nil if absent.

Arguments
NameTypeDescription
selfResponse
namestring
Returns
TypeDescription
string?

headerValuesmethod#

headerValues: function(self: Response, name: string): {string}
@readonly

Returns all values for a case-insensitive header name.

Arguments
NameTypeDescription
selfResponse
namestring
Returns
TypeDescription
{string}

headersmethod#

headers: function(self: Response): {[string]: string}
@readonly

Returns a fresh response header mapping keyed by lowercase name. Repeated values are joined with , except set-cookie, whose first value is returned; use headerValues to preserve every value.

Arguments
NameTypeDescription
selfResponse
Returns
TypeDescription
{[string]: string}