[][src]Struct gdnative::api::HTTPClient

pub struct HTTPClient { /* fields omitted */ }

core class HTTPClient inherits Reference (reference counted).

Official documentation

See the documentation of this class in the Godot engine's official documentation.

Memory management

The lifetime of this object is automatically managed through reference counting.

Class hierarchy

HTTPClient inherits methods from:

Safety

All types in the Godot API have "interior mutability" in Rust parlance. To enforce that the official thread-safety guidelines are followed, the typestate pattern is used in the Ref and TRef smart pointers, and the Instance API. The typestate Access in these types tracks whether the access is unique, shared, or exclusive to the current thread. For more information, see the type-level documentation on Ref.

Implementations

impl HTTPClient[src]

Constants

pub const METHOD_CONNECT: i64[src]

pub const METHOD_DELETE: i64[src]

pub const METHOD_GET: i64[src]

pub const METHOD_HEAD: i64[src]

pub const METHOD_MAX: i64[src]

pub const METHOD_OPTIONS: i64[src]

pub const METHOD_PATCH: i64[src]

pub const METHOD_POST: i64[src]

pub const METHOD_PUT: i64[src]

pub const METHOD_TRACE: i64[src]

pub const RESPONSE_ACCEPTED: i64[src]

pub const RESPONSE_ALREADY_REPORTED: i64[src]

pub const RESPONSE_BAD_GATEWAY: i64[src]

pub const RESPONSE_BAD_REQUEST: i64[src]

pub const RESPONSE_CONFLICT: i64[src]

pub const RESPONSE_CONTINUE: i64[src]

pub const RESPONSE_CREATED: i64[src]

pub const RESPONSE_EXPECTATION_FAILED: i64[src]

pub const RESPONSE_FAILED_DEPENDENCY: i64[src]

pub const RESPONSE_FORBIDDEN: i64[src]

pub const RESPONSE_FOUND: i64[src]

pub const RESPONSE_GATEWAY_TIMEOUT: i64[src]

pub const RESPONSE_GONE: i64[src]

pub const RESPONSE_HTTP_VERSION_NOT_SUPPORTED: i64[src]

pub const RESPONSE_IM_A_TEAPOT: i64[src]

pub const RESPONSE_IM_USED: i64[src]

pub const RESPONSE_INSUFFICIENT_STORAGE: i64[src]

pub const RESPONSE_INTERNAL_SERVER_ERROR: i64[src]

pub const RESPONSE_LENGTH_REQUIRED: i64[src]

pub const RESPONSE_LOCKED: i64[src]

pub const RESPONSE_LOOP_DETECTED: i64[src]

pub const RESPONSE_METHOD_NOT_ALLOWED: i64[src]

pub const RESPONSE_MISDIRECTED_REQUEST: i64[src]

pub const RESPONSE_MOVED_PERMANENTLY: i64[src]

pub const RESPONSE_MULTIPLE_CHOICES: i64[src]

pub const RESPONSE_MULTI_STATUS: i64[src]

pub const RESPONSE_NETWORK_AUTH_REQUIRED: i64[src]

pub const RESPONSE_NON_AUTHORITATIVE_INFORMATION: i64[src]

pub const RESPONSE_NOT_ACCEPTABLE: i64[src]

pub const RESPONSE_NOT_EXTENDED: i64[src]

pub const RESPONSE_NOT_FOUND: i64[src]

pub const RESPONSE_NOT_IMPLEMENTED: i64[src]

pub const RESPONSE_NOT_MODIFIED: i64[src]

pub const RESPONSE_NO_CONTENT: i64[src]

pub const RESPONSE_OK: i64[src]

pub const RESPONSE_PARTIAL_CONTENT: i64[src]

pub const RESPONSE_PAYMENT_REQUIRED: i64[src]

pub const RESPONSE_PERMANENT_REDIRECT: i64[src]

pub const RESPONSE_PRECONDITION_FAILED: i64[src]

pub const RESPONSE_PRECONDITION_REQUIRED: i64[src]

pub const RESPONSE_PROCESSING: i64[src]

pub const RESPONSE_PROXY_AUTHENTICATION_REQUIRED: i64[src]

pub const RESPONSE_REQUESTED_RANGE_NOT_SATISFIABLE: i64[src]

pub const RESPONSE_REQUEST_ENTITY_TOO_LARGE: i64[src]

pub const RESPONSE_REQUEST_HEADER_FIELDS_TOO_LARGE: i64[src]

pub const RESPONSE_REQUEST_TIMEOUT: i64[src]

pub const RESPONSE_REQUEST_URI_TOO_LONG: i64[src]

pub const RESPONSE_RESET_CONTENT: i64[src]

pub const RESPONSE_SEE_OTHER: i64[src]

pub const RESPONSE_SERVICE_UNAVAILABLE: i64[src]

pub const RESPONSE_SWITCHING_PROTOCOLS: i64[src]

pub const RESPONSE_SWITCH_PROXY: i64[src]

pub const RESPONSE_TEMPORARY_REDIRECT: i64[src]

pub const RESPONSE_TOO_MANY_REQUESTS: i64[src]

pub const RESPONSE_UNAUTHORIZED: i64[src]

pub const RESPONSE_UNPROCESSABLE_ENTITY: i64[src]

pub const RESPONSE_UNSUPPORTED_MEDIA_TYPE: i64[src]

pub const RESPONSE_UPGRADE_REQUIRED: i64[src]

pub const RESPONSE_USE_PROXY: i64[src]

pub const RESPONSE_VARIANT_ALSO_NEGOTIATES: i64[src]

pub const STATUS_BODY: i64[src]

pub const STATUS_CANT_CONNECT: i64[src]

pub const STATUS_CANT_RESOLVE: i64[src]

pub const STATUS_CONNECTED: i64[src]

pub const STATUS_CONNECTING: i64[src]

pub const STATUS_CONNECTION_ERROR: i64[src]

pub const STATUS_DISCONNECTED: i64[src]

pub const STATUS_REQUESTING: i64[src]

pub const STATUS_RESOLVING: i64[src]

pub const STATUS_SSL_HANDSHAKE_ERROR: i64[src]

impl HTTPClient[src]

pub fn new() -> Ref<HTTPClient, Unique>[src]

Creates a new instance of this object.

This is a reference-counted type. The returned object is automatically managed by Ref.

pub fn close(&self)[src]

Closes the current connection, allowing reuse of this [HTTPClient].

pub fn connect_to_host(
    &self,
    host: impl Into<GodotString>,
    port: i64,
    use_ssl: bool,
    verify_host: bool
) -> Result<(), GodotError>
[src]

Connects to a host. This needs to be done before any requests are sent.
				The host should not have http:// prepended but will strip the protocol identifier if provided.
				If no [code]port[/code] is specified (or [code]-1[/code] is used), it is automatically set to 80 for HTTP and 443 for HTTPS (if [code]use_ssl[/code] is enabled).
				[code]verify_host[/code] will check the SSL identity of the host if set to [code]true[/code].

Default Arguments

  • port - -1
  • use_ssl - false
  • verify_host - true

pub fn connection(&self) -> Option<Ref<StreamPeer, Shared>>[src]

The connection to use for this client.

pub fn read_chunk_size(&self) -> i64[src]

The size of the buffer used and maximum bytes to read per iteration. See [method read_response_body_chunk].

pub fn get_response_body_length(&self) -> i64[src]

Returns the response's body length.
				[b]Note:[/b] Some Web servers may not send a body length. In this case, the value returned will be [code]-1[/code]. If using chunked transfer encoding, the body length will also be [code]-1[/code].

pub fn get_response_code(&self) -> i64[src]

Returns the response's HTTP status code.

pub fn get_response_headers(&self) -> TypedArray<GodotString>[src]

Returns the response headers.

pub fn get_response_headers_as_dictionary(&self) -> Dictionary<Shared>[src]

Returns all response headers as a Dictionary of structure [code]{ "key": "value1; value2" }[/code] where the case-sensitivity of the keys and values is kept like the server delivers it. A value is a simple String, this string can have more than one value where "; " is used as separator.
				[b]Example:[/b]
				[codeblock]
				{
				    "content-length": 12,
				    "Content-Type": "application/json; charset=UTF-8",
				}
				[/codeblock]

pub fn get_status(&self) -> Status[src]

Returns a [enum Status] constant. Need to call [method poll] in order to get status updates.

pub fn has_response(&self) -> bool[src]

If [code]true[/code], this [HTTPClient] has a response available.

pub fn is_blocking_mode_enabled(&self) -> bool[src]

If [code]true[/code], execution will block until all data is read from the response.

pub fn is_response_chunked(&self) -> bool[src]

If [code]true[/code], this [HTTPClient] has a response that is chunked.

pub fn poll(&self) -> Result<(), GodotError>[src]

This needs to be called in order to have any request processed. Check results with [method get_status].

pub fn query_string_from_dict(&self, fields: Dictionary<Shared>) -> GodotString[src]

Generates a GET/POST application/x-www-form-urlencoded style query string from a provided dictionary, e.g.:
				[codeblock]
				var fields = {"username": "user", "password": "pass"}
				var query_string = http_client.query_string_from_dict(fields)
				# Returns "username=user&password=pass"
				[/codeblock]
				Furthermore, if a key has a [code]null[/code] value, only the key itself is added, without equal sign and value. If the value is an array, for each value in it a pair with the same key is added.
				[codeblock]
				var fields = {"single": 123, "not_valued": null, "multiple": [22, 33, 44]}
				var query_string = http_client.query_string_from_dict(fields)
				# Returns "single=123&not_valued&multiple=22&multiple=33&multiple=44"
				[/codeblock]

pub fn read_response_body_chunk(&self) -> TypedArray<u8>[src]

Reads one chunk from the response.

pub fn request(
    &self,
    method: i64,
    url: impl Into<GodotString>,
    headers: TypedArray<GodotString>,
    body: impl Into<GodotString>
) -> Result<(), GodotError>
[src]

Sends a request to the connected host. The URL parameter is just the part after the host, so for [code]http://somehost.com/index.php[/code], it is [code]index.php[/code].
				Headers are HTTP request headers. For available HTTP methods, see [enum Method].
				To create a POST request with query strings to push to the server, do:
				[codeblock]
				var fields = {"username" : "user", "password" : "pass"}
				var query_string = http_client.query_string_from_dict(fields)
				var headers = ["Content-Type: application/x-www-form-urlencoded", "Content-Length: " + str(query_string.length())]
				var result = http_client.request(http_client.METHOD_POST, "index.php", headers, query_string)
				[/codeblock]
				[b]Note:[/b] The [code]request_data[/code] parameter is ignored if [code]method[/code] is [constant HTTPClient.METHOD_GET]. This is because GET methods can't contain request data. As a workaround, you can pass request data as a query string in the URL. See [method String.http_escape] for an example.

Default Arguments

  • body - ""

pub fn request_raw(
    &self,
    method: i64,
    url: impl Into<GodotString>,
    headers: TypedArray<GodotString>,
    body: TypedArray<u8>
) -> Result<(), GodotError>
[src]

Sends a raw request to the connected host. The URL parameter is just the part after the host, so for [code]http://somehost.com/index.php[/code], it is [code]index.php[/code].
				Headers are HTTP request headers. For available HTTP methods, see [enum Method].
				Sends the body data raw, as a byte array and does not encode it in any way.

pub fn set_blocking_mode(&self, enabled: bool)[src]

If [code]true[/code], execution will block until all data is read from the response.

pub fn set_connection(&self, connection: impl AsArg<StreamPeer>)[src]

The connection to use for this client.

pub fn set_read_chunk_size(&self, bytes: i64)[src]

The size of the buffer used and maximum bytes to read per iteration. See [method read_response_body_chunk].

Methods from Deref<Target = Reference>

pub fn init_ref(&self) -> bool[src]

Initializes the internal reference counter. Use this only if you really know what you are doing.
				Returns whether the initialization was successful.

Trait Implementations

impl Debug for HTTPClient[src]

impl Deref for HTTPClient[src]

type Target = Reference

The resulting type after dereferencing.

impl DerefMut for HTTPClient[src]

impl GodotObject for HTTPClient[src]

type RefKind = RefCounted

The memory management kind of this type. This modifies the behavior of the Ref smart pointer. See its type-level documentation for more information. Read more

impl Instanciable for HTTPClient[src]

impl SubClass<Object> for HTTPClient[src]

impl SubClass<Reference> for HTTPClient[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> SubClass<T> for T where
    T: GodotObject
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.