package wasi:http@0.2.0; interface types { use wasi:clocks/monotonic-clock@0.2.0.{duration}; use wasi:io/streams@0.2.0.{input-stream, output-stream}; use wasi:io/error@0.2.0.{error as io-error}; use wasi:io/poll@0.2.0.{pollable}; variant method { get, head, post, put, delete, connect, options, trace, patch, other(string), } variant scheme { HTTP, HTTPS, other(string), } record DNS-error-payload { rcode: option, info-code: option, } record TLS-alert-received-payload { alert-id: option, alert-message: option, } record field-size-payload { field-name: option, field-size: option, } variant error-code { DNS-timeout, DNS-error(DNS-error-payload), destination-not-found, destination-unavailable, destination-IP-prohibited, destination-IP-unroutable, connection-refused, connection-terminated, connection-timeout, connection-read-timeout, connection-write-timeout, connection-limit-reached, TLS-protocol-error, TLS-certificate-error, TLS-alert-received(TLS-alert-received-payload), HTTP-request-denied, HTTP-request-length-required, HTTP-request-body-size(option), HTTP-request-method-invalid, HTTP-request-URI-invalid, HTTP-request-URI-too-long, HTTP-request-header-section-size(option), HTTP-request-header-size(option), HTTP-request-trailer-section-size(option), HTTP-request-trailer-size(field-size-payload), HTTP-response-incomplete, HTTP-response-header-section-size(option), HTTP-response-header-size(field-size-payload), HTTP-response-body-size(option), HTTP-response-trailer-section-size(option), HTTP-response-trailer-size(field-size-payload), HTTP-response-transfer-coding(option), HTTP-response-content-coding(option), HTTP-response-timeout, HTTP-upgrade-failed, HTTP-protocol-error, loop-detected, configuration-error, internal-error(option), } variant header-error { invalid-syntax, forbidden, immutable, } type field-key = string; type field-value = list; resource fields { constructor(); from-list: static func(entries: list>) -> result; get: func(name: field-key) -> list; has: func(name: field-key) -> bool; set: func(name: field-key, value: list) -> result<_, header-error>; delete: func(name: field-key) -> result<_, header-error>; append: func(name: field-key, value: field-value) -> result<_, header-error>; entries: func() -> list>; clone: func() -> fields; } type headers = fields; type trailers = fields; resource incoming-request { method: func() -> method; path-with-query: func() -> option; scheme: func() -> option; authority: func() -> option; headers: func() -> headers; consume: func() -> result; } resource outgoing-request { constructor(headers: headers); body: func() -> result; method: func() -> method; set-method: func(method: method) -> result; path-with-query: func() -> option; set-path-with-query: func(path-with-query: option) -> result; scheme: func() -> option; set-scheme: func(scheme: option) -> result; authority: func() -> option; set-authority: func(authority: option) -> result; headers: func() -> headers; } resource request-options { constructor(); connect-timeout: func() -> option; set-connect-timeout: func(duration: option) -> result; first-byte-timeout: func() -> option; set-first-byte-timeout: func(duration: option) -> result; between-bytes-timeout: func() -> option; set-between-bytes-timeout: func(duration: option) -> result; } resource response-outparam { set: static func(param: response-outparam, response: result); } type status-code = u16; resource incoming-response { status: func() -> status-code; headers: func() -> headers; consume: func() -> result; } resource incoming-body { %stream: func() -> result; finish: static func(this: incoming-body) -> future-trailers; } resource future-trailers { subscribe: func() -> pollable; get: func() -> option, error-code>>>; } resource outgoing-response { constructor(headers: headers); status-code: func() -> status-code; set-status-code: func(status-code: status-code) -> result; headers: func() -> headers; body: func() -> result; } resource outgoing-body { write: func() -> result; finish: static func(this: outgoing-body, trailers: option) -> result<_, error-code>; } resource future-incoming-response { subscribe: func() -> pollable; get: func() -> option>>; } http-error-code: func(err: borrow) -> option; } interface incoming-handler { use types.{incoming-request, response-outparam}; handle: func(request: incoming-request, response-out: response-outparam); } interface outgoing-handler { use types.{outgoing-request, request-options, future-incoming-response, error-code}; handle: func(request: outgoing-request, options: option) -> result; }