Skip to content

fn cleanup #

fn cleanup()

cleanup releases resources that were acquired initializing the underlying libcurl module.

fn custom_init #

fn custom_init(flag CustomInitFlag)

custom_init initializes libcurl with a custom flag.

fn download_file #

fn download_file(url string, file_path string) !Response

download_file downloads a document from the specified url and saves it to the specified file_path.

fn download_file_with_progress #

fn download_file_with_progress(url string, file_path string, mut download Download) !Response

download_file_with_progress downloads a document from the specified url and saves it to the specified file_path. download must implement a progress(pos u64, size u64), and a finish() method.

fn get #

fn get(url string) !Response

get sends a GET request to the specified url and returns the response.

fn get_slice #

fn get_slice(url string, start usize, max_size ?usize) !Response

get_slice sends a GET request to the specified url and returns a slice of the response content. Allocation of the received response as a vstring is postponed until the start byte position is reached. The content is returned as soon as the slice reaches its max_size (offset from start)- max_size can be none to return the remainder from the start.

fn post #

fn post(url string, data string) !Response

post sends a POST request to the specified url and returns the response.

interface Download #

interface Download {
mut:
	progress(u64, u64)
	finish()
}

type CustomInitFlag #

type CustomInitFlag = state.GlobalInitFlag

fn (Status) msg #

fn (status Status) msg() string

msg returns the message associated with the status code.

enum HttpHeader #

@[generated]
enum HttpHeader {
	accept
	accept_ch
	accept_charset
	accept_encoding
	accept_language
	accept_patch
	accept_post
	accept_ranges
	access_control_allow_credentials
	access_control_allow_headers
	access_control_allow_methods
	access_control_allow_origin
	access_control_expose_headers
	access_control_max_age
	access_control_request_headers
	access_control_request_method
	age
	allow
	alt_svc
	authorization
	cache_control
	clear_site_data
	connection
	content_disposition
	content_encoding
	content_language
	content_length
	content_location
	content_range
	content_security_policy
	content_security_policy_report_only
	content_type
	cookie
	critical_ch // Experimental
	cross_origin_embedder_policy
	cross_origin_opener_policy
	cross_origin_resource_policy
	date
	device_memory // Experimental
	digest
	downlink   // Experimental
	early_data // Experimental
	ect        // Experimental
	etag
	expect
	expect_ct
	expires
	forwarded
	from
	host
	if_match
	if_modified_since
	if_none_match
	if_range
	if_unmodified_since
	keep_alive
	last_modified
	link
	location
	max_forwards
	nel // Experimental
	origin
	permissions_policy
	proxy_authenticate
	proxy_authorization
	range
	referer
	referrer_policy
	retry_after
	rtt                           // Experimental
	save_data                     // Experimental
	sec_ch_prefers_reduced_motion // Experimental
	sec_ch_ua                     // Experimental
	sec_ch_ua_arch                // Experimental
	sec_ch_ua_bitness             // Experimental
	sec_ch_ua_full_version_list   // Experimental
	sec_ch_ua_mobile              // Experimental
	sec_ch_ua_model               // Experimental
	sec_ch_ua_platform            // Experimental
	sec_ch_ua_platform_version    // Experimental
	sec_fetch_dest
	sec_fetch_mode
	sec_fetch_site
	sec_fetch_user
	sec_gpc // Experimental
	sec_websocket_accept
	server
	server_timing
	service_worker_navigation_preload
	set_cookie
	sourcemap
	strict_transport_security
	te
	timing_allow_origin
	trailer
	transfer_encoding
	upgrade
	upgrade_insecure_requests
	user_agent
	vary
	via
	want_digest
	www_authenticate
	x_content_type_options
	x_dns_prefetch_control // Non-standard
	x_forwarded_for        // Non-standard
	x_forwarded_host       // Non-standard
	x_forwarded_proto      // Non-standard
	x_frame_options
	x_xss_protection // Non-standard
}

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers

fn (HttpHeader) str #

fn (header HttpHeader) str() string

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers

enum SSLLevel #

enum SSLLevel {
	@none
	try
	control
	all
}

Todo:

struct ProxySettings #

struct ProxySettings {
pub mut:
	address  string
	port     u16
	user     string
	password string
}

struct Request #

struct Request {
pub mut:
	headers        map[HttpHeader]string
	custom_headers map[string]string
	cookie_jar     string
	cookie_file    string
	proxy          ProxySettings
	timeout        time.Duration
	max_redirects  u16 = 10
}

fn (Request) download_file #

fn (req Request) download_file(url string, file_path string) !Response

download_file downloads a document from the specified url and saves it to the specified file_path.

fn (Request) download_file_with_progress #

fn (req Request) download_file_with_progress(url string, file_path string, mut download Download) !Response

download_file_with_progress downloads a document from the specified url and saves it to the specified file_path. download must implement a progress(pos u64, size u64), and a finish() method.

fn (Request) get #

fn (req Request) get(url string) !Response

get send a GET request to the specified url and returns the response.

fn (Request) get_slice #

fn (req Request) get_slice(url string, start usize, max_size ?usize) !Response

get_slice sends a GET request to the specified url and returns a slice of the response content. Allocation of the received response as a vstring is postponed until the start byte position is reached. The content is returned as soon as the slice reaches its max_size (offset from start)- max_size can be none to return the remainder from the start.

fn (Request) head #

fn (req Request) head(url string) !Response

head sends a HEAD request to the specified url and returns the response.

fn (Request) post #

fn (req Request) post(url string, data string) !Response

post sends a POST request to the specified url and returns the response.

struct Response #

struct Response {
pub mut:
	header       string
	status       Status
	http_version string
	body         string
}