net/http

sourcenet/http.sx

curl_easy_init

when posixprivate
extern (C) fn curl_easy_init() ref void = trust { ... } = "curl_easy_init"

curl_easy_cleanup

when posixprivate
extern (C) fn curl_easy_cleanup(handle: ref void) void = trust { ... } = "curl_easy_cleanup"

curl_easy_setopt

when posixprivate
extern (C) fn curl_easy_setopt(handle: ref void, opt: i32, ...) i64 = trust { ... } = "curl_easy_setopt"

curl_easy_perform

when posixprivate
extern (C) fn curl_easy_perform(handle: ref void) i64 = trust { ... } = "curl_easy_perform"

curl_easy_getinfo

when posixprivate
extern (C) fn curl_easy_getinfo(handle: ref void, info: i32, ...) i64 = trust { ... } = "curl_easy_getinfo"

curl_slist_append

when posixprivate
extern (C) fn curl_slist_append(list: ref void, str: ref u8) ref void = trust { ... } = "curl_slist_append"

curl_slist_free_all

when posixprivate
extern (C) fn curl_slist_free_all(list: ref void) void = trust { ... } = "curl_slist_free_all"

curl_global_init

when posixprivate
extern (C) fn curl_global_init(flags: i64) i64 = trust { ... } = "curl_global_init"

curl_global_cleanup

when posixprivate
extern (C) fn curl_global_cleanup() void = trust { ... } = "curl_global_cleanup"

InternetOpenA

when windowsprivate
extern (C, header) fn InternetOpenA(agent: ref u8, access: u32, proxy: ref u8, bypass: ref u8, flags: u32) ref void = trust { ... } = "InternetOpenA"

InternetConnectA

when windowsprivate
extern (C, header) fn InternetConnectA(handle: ref void, server: ref u8, port: u16, user: ref u8, password: ref u8, service: u32, flags: u32, context: usize) ref void = trust { ... } = "InternetConnectA"

HttpOpenRequestA

when windowsprivate
extern (C, header) fn HttpOpenRequestA(handle: ref void, verb: ref u8, path: ref u8, version: ref u8, referrer: ref void, accept: ref void, flags: u32, context: usize) ref void = trust { ... } = "HttpOpenRequestA"

HttpSendRequestA

when windowsprivate
extern (C, header) fn HttpSendRequestA(handle: ref void, headers: ref u8, headers_len: u32, optional: ref void, optional_len: u32) i32 = trust { ... } = "HttpSendRequestA"

HttpQueryInfoA

when windowsprivate
extern (C, header) fn HttpQueryInfoA(handle: ref void, info: u32, buf: ref void, len: ref u32, index: ref u32) i32 = trust { ... } = "HttpQueryInfoA"

InternetReadFile

when windowsprivate
extern (C, header) fn InternetReadFile(handle: ref void, buf: ref void, len: u32, read: ref u32) i32 = trust { ... } = "InternetReadFile"

InternetCloseHandle

when windowsprivate
extern (C, header) fn InternetCloseHandle(handle: ref void) i32 = trust { ... } = "InternetCloseHandle"

CURLOPT_URL

pub val CURLOPT_URL = 10002

CURLOPT_WRITEFUNCTION

pub val CURLOPT_WRITEFUNCTION = 20011

CURLOPT_WRITEDATA

pub val CURLOPT_WRITEDATA = 10001

CURLOPT_HTTPHEADER

pub val CURLOPT_HTTPHEADER = 10023

CURLOPT_POSTFIELDS

pub val CURLOPT_POSTFIELDS = 10015

CURLOPT_POSTFIELDSIZE

pub val CURLOPT_POSTFIELDSIZE = 60

CURLOPT_CUSTOMREQUEST

pub val CURLOPT_CUSTOMREQUEST = 10036

CURLOPT_FOLLOWLOCATION

pub val CURLOPT_FOLLOWLOCATION = 52

CURLOPT_MAXREDIRS

pub val CURLOPT_MAXREDIRS = 68

CURLINFO_RESPONSE_CODE

pub val CURLINFO_RESPONSE_CODE = 2097154

CURL_GLOBAL_DEFAULT

pub val CURL_GLOBAL_DEFAULT = 3

Buffer

type Buffer = { data: mut ref void, len: mut i64, cap: mut i64, failed: mut bool }

Fields

NameType
datamut ref void
lenmut i64
capmut i64
failedmut bool

Response

type Response = { body: mut ref u8, status: mut i64, len: mut i64 }

An owned HTTP response.

Fields

NameType
bodymut ref u8
statusmut i64
lenmut i64

I32Slot

type I32Slot = { value: mut i32 }

Fields

NameType
valuemut i32

I64Slot

type I64Slot = { value: mut i64 }

Fields

NameType
valuemut i64

WinUrl

type WinUrl = { secure: mut bool, host: mut ref u8, port: mut u16, path: mut ref u8 }

Fields

NameType
securemut bool
hostmut ref u8
portmut u16
pathmut ref u8

WinHeader

type WinHeader = { next: mut ref void, value: mut ref u8 }

Fields

NameType
nextmut ref void
valuemut ref u8

buf_new

private
fn buf_new() ref Buffer = trust { ... }

buf_append

private
fn buf_append(buf: mut ref Buffer, data: ref void, total: i64) bool = trust { ... }

curl_write_cb

pub fn curl_write_cb(ptr: ref void, size: i64, nmemb: i64, userdata: ref void) i64 = trust { ... }

Internal write callback for curl. Signature matches: size_t write_fn(u8 *ptr, size_t size, size_t nmemb, void *userdata)

response_new

private
fn response_new[A: allocators.GeneralAllocator](ac: A, status: i64, body_ptr: ref void, body_len: i64) ref Response

Allocate a Response from a raw body using the provided allocator.

do_request

when posixprivate
fn do_request[A: allocators.GeneralAllocator](ac: A, handle: ref void) ref Response

win_char

private
fn win_char(s: ref u8, i: i64) u8 = trust { ... }

win_url_free

private
fn win_url_free(url: ref WinUrl) void = trust { ... }

win_parse_url

private
fn win_parse_url(url: ref u8) ref WinUrl = trust { ... }

Parse an http:// or https:// URL into the pieces WinINet needs.

win_header_new

private
fn win_header_new(value: ref u8) ref void = trust { ... }

win_header_append

private
fn win_header_append(list: ref void, value: ref u8) ref void = trust { ... }

win_header_free

private
fn win_header_free(list: ref void) void = trust { ... }

win_headers_build

private
fn win_headers_build(list: ref void) ref u8 = trust { ... }

Join our header list into the CRLF-separated block WinINet expects.

win_query_status

when windowsprivate
fn win_query_status(handle: ref void) i64 = trust { ... }

win_do_request

when windowsprivate
fn win_do_request[A: allocators.GeneralAllocator](ac: A, method: ref u8, url: ref u8, body: ref u8, header_list: ref void) ref Response

Perform an HTTP request with WinINet. Returns a Response allocated with the provided allocator.

Http

type Http = {  }

init

pub fn (Http) init() void

Initialise the HTTP client global state. Call once at program start.

cleanup

pub fn (Http) cleanup() void = trust { ... }

Clean up the HTTP client global state. Call once at program end.

get

pub fn (Http) get[A: allocators.GeneralAllocator](ac: A, url: ref u8) ref Response

Perform an HTTP GET request. Returns a Response allocated with the provided allocator; caller must call Http.free_response().

post_request

pub fn (Http) post_request[A: allocators.GeneralAllocator](ac: A, url: ref u8, body: ref u8, content_type: ref u8) ref Response

Perform an HTTP POST request with a body str. Returns a Response allocated with the provided allocator; caller must call Http.free_response().

request

pub fn (Http) request[A: allocators.GeneralAllocator](ac: A, method: ref u8, url: ref u8, body: ref u8, headers: ref void) ref Response

Perform an arbitrary HTTP request (GET, POST, PUT, DELETE, PATCH …).

free_response

pub fn (Http) free_response[A: allocators.GeneralAllocator](ac: A, resp: ref Response) void

Free a Response returned by Http.get / Http.post / Http.request with the same allocator used to create it.

status

pub fn (Http) status(resp: ref Response) i64

Read the HTTP status code from a Response.

body

pub fn (Http) body(resp: ref Response) ref u8

Read the body pointer from a Response.

body_len

pub fn (Http) body_len(resp: ref Response) i64

Read the body length from a Response.

make_headers

pub fn (Http) make_headers(header: ref u8) ref void = trust { ... }

Build a header list from a single "Key: Value" str.

append_header

pub fn (Http) append_header(list: ref void, header: ref u8) ref void = trust { ... }

Append a header to an existing header list.

free_headers

pub fn (Http) free_headers(list: ref void) void = trust { ... }

Free a header list created with Http.make_headers / Http.append_header.