net.http #

fn delete #

fn delete(url string) ?Response

fn download_file #

fn download_file(url string, out string) ?

fn download_file_with_progress #

fn download_file_with_progress(url string, out string, cb DownloadFn, cb_finished fn ())

fn escape #

fn escape(s string) string

fn escape_url #

fn escape_url(s string) string

fn fetch #

fn fetch(_url string, config FetchConfig) ?Response

fn get #

fn get(url string) ?Response

fn get_text #

fn get_text(url string) string

fn method_from_str #

fn method_from_str(m string) Method

fn new_request #

fn new_request(method Method, url_ string, data string) ?Request

fn parse_headers #

fn parse_headers(lines []string) map[string]string

fn patch #

fn patch(url string, data string) ?Response

fn post #

fn post(url string, data string) ?Response

fn post_form #

fn post_form(url string, data map[string]string) ?Response

fn post_json #

fn post_json(url string, data string) ?Response

fn put #

fn put(url string, data string) ?Response

fn read_cookies #

fn read_cookies(h map[string][]string, filter string) []&Cookie

Parses all "Cookie" values from the header h and returns the successfully parsed Cookies. if filter isn't empty, only cookies of that name are returned

fn read_set_cookies #

fn read_set_cookies(h map[string][]string) []&Cookie

Parses all "Set-Cookie" values from the header h and returns the successfully parsed Cookies.

fn status_from_int #

fn status_from_int(code int) Status

fn unescape #

fn unescape(s string) string

fn unescape_url #

fn unescape_url(s string) string

fn url_encode_form_data #

fn url_encode_form_data(data map[string]string) string

enum Method #

enum Method {
	get
	post
	put
	head
	delete
	options
	trace
	connect
	patch
}

The methods listed here are some of the most used ones, ordered by commonality. A comprehensive list is available at: https://www.iana.org/assignments/http-methods/http-methods.xhtml

fn (Method) str #

fn (m Method) str() string

enum SameSite #

enum SameSite {
	same_site_default_mode = 1
	same_site_lax_mode
	same_site_strict_mode
	same_site_none_mode
}

SameSite allows a server to define a cookie attribute making it impossible for the browser to send this cookie along with cross-site requests. The main goal is to mitigate the risk of cross-origin information leakage, and provide some protection against cross-site request forgery attacks. See https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00 for details.

enum Status #

enum Status {
	unknown = -1
	unassigned = 0
	cont = 100
	switching_protocols = 101
	processing = 102
	checkpoint_draft = 103
	ok = 200
	created = 201
	accepted = 202
	non_authoritative_information = 203
	no_content = 204
	reset_content = 205
	partial_content = 206
	multi_status = 207
	already_reported = 208
	im_used = 226
	multiple_choices = 300
	moved_permanently = 301
	found = 302
	see_other = 303
	not_modified = 304
	use_proxy = 305
	switch_proxy = 306
	temporary_redirect = 307
	permanent_redirect = 308
	bad_request = 400
	unauthorized = 401
	payment_required = 402
	forbidden = 403
	not_found = 404
	method_not_allowed = 405
	not_acceptable = 406
	proxy_authentication_required = 407
	request_timeout = 408
	conflict = 409
	gone = 410
	length_required = 411
	precondition_failed = 412
	request_entity_too_large = 413
	request_uri_too_long = 414
	unsupported_media_type = 415
	requested_range_not_satisfiable = 416
	expectation_failed = 417
	im_a_teapot = 418
	misdirected_request = 421
	unprocessable_entity = 422
	locked = 423
	failed_dependency = 424
	unordered_collection = 425
	upgrade_required = 426
	precondition_required = 428
	too_many_requests = 429
	request_header_fields_too_large = 431
	unavailable_for_legal_reasons = 451
	client_closed_request = 499
	internal_server_error = 500
	not_implemented = 501
	bad_gateway = 502
	service_unavailable = 503
	gateway_timeout = 504
	http_version_not_supported = 505
	variant_also_negotiates = 506
	insufficient_storage = 507
	loop_detected = 508
	bandwidth_limit_exceeded = 509
	not_extended = 510
	network_authentication_required = 511
}

The status codes listed here are based on the comprehensive list, available at: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml

fn (Status) str #

fn (code Status) str() string

fn (Status) int #

fn (code Status) int() int

int converts an assigned and known Status to its integral equivalent. if a Status is unknown or unassigned, this method will return zero

fn (Status) is_valid #

fn (code Status) is_valid() bool

is_valid returns true if the status code is assigned and known

fn (Status) is_error #

fn (code Status) is_error() bool

is_error will return true if the status code represents either a client or a server error; otherwise will return false

fn (Status) is_success #

fn (code Status) is_success() bool

is_success will return true if the status code represents either an informational, success, or redirection response; otherwise will return false

fn (Cookie) str #

fn (c &Cookie) str() string

Returns the serialization of the cookie for use in a Cookie header (if only Name and Value are set) or a Set-Cookie response header (if other fields are set). If c.name is invalid, the empty string is returned.

struct FetchConfig #

struct FetchConfig {
pub mut:
	method     Method
	data       string
	params     map[string]string
	headers    map[string]string
	cookies    map[string]string
	user_agent string = 'v.http'
	verbose    bool
}

struct Request #

struct Request {
pub mut:
	method     Method
	headers    map[string]string
	cookies    map[string]string
	data       string
	url        string
	user_agent string = 'v.http'
	verbose    bool
	user_ptr   voidptr
	ws_func    voidptr
}

fn (Request) add_header #

fn (mut req Request) add_header(key string, val string)

add_header adds the key and value of an HTTP request header

fn (Request) do #

fn (req &Request) do() ?Response

do will send the HTTP request and returns http.Response as soon as the response is recevied

fn (Request) referer #

fn (req &Request) referer() string

struct Response #

struct Response {
pub:
	text        string
	headers     map[string]string
	lheaders    map[string]string
	cookies     map[string]string
	status_code int
}