HTTPRequest
A node with the ability to send HTTP(S) requests.
HTTPRequest.swift:35class HTTPRequest
A node with the ability to send HTTP requests. Uses HTTPClient
internally.
Can be used to make HTTP requests, i.e. download or upload files or web content via HTTP.
Example of contacting a REST API and printing one of its returned fields:
Example of loading and displaying an image using HTTPRequest:
Gzipped response bodies: HTTPRequest will automatically handle decompression of response bodies. A Accept-Encoding
header will be automatically added to each of your requests, unless one is already specified. Any response with a Content-Encoding: gzip
header will automatically be decompressed and delivered to you as uncompressed bytes.
This object emits the following signals:
Superclasses
class Node
Base class for all scene objects.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Types
enum Result
class Signal1
Signal support.
Type members
Instance members
var acceptGzip: Bool
If
true
, this header will be added to each request:Accept-Encoding: gzip, deflate
telling servers that it’s okay to compress response bodies.var bodySizeLimit: Int32
Maximum allowed size for response bodies. If the response body is compressed, this will be used as the maximum allowed size for the decompressed body.
var downloadChunkSize: Int32
The size of the buffer used and maximum bytes to read per iteration. See
readChunkSize
.var downloadFile: String
The file to download into. Will output any received file into it.
var maxRedirects: Int32
Maximum number of allowed redirects.
var requestCompleted: Signal1
Emitted when a request is completed.
var timeout: Double
The duration to wait in seconds before a request times out. If
timeout
is set to0.0
then the request will never time out. For simple requests, such as communication with a REST API, it is recommended thattimeout
is set to a value suitable for the server response time (e.g. between1.0
and10.0
). This will help prevent unwanted timeouts caused by variation in server response times while still allowing the application to detect when a request has timed out. For larger requests such as file downloads it is suggested thetimeout
be set to0.0
, disabling the timeout functionality. This will help to prevent large transfers from failing due to exceeding the timeout value.var useThreads: Bool
If
true
, multithreading is used to improve performance.func cancelRequest(
) Cancels the current request.
func getBodySize(
) -> Int32 Returns the response body length.
func getDownloadedBytes(
) -> Int32 Returns the number of bytes this HTTPRequest downloaded.
func getHttpClientStatus(
) -> HTTPClient.Status Returns the current status of the underlying
HTTPClient
. SeeHTTPClient.Status
.func request(url: String, customHeaders: PackedStringArray, method: HTTPClient.Method, requestData: String
) -> GodotError Creates request on the underlying
HTTPClient
. If there is no configuration errors, it tries to connect usingconnectToHost(_:port:tlsOptions:)
and passes parameters ontorequest(method:url:headers:body:)
.func requestRaw(url: String, customHeaders: PackedStringArray, method: HTTPClient.Method, requestDataRaw: PackedByteArray
) -> GodotError Creates request on the underlying
HTTPClient
using a raw array of bytes for the request body. If there is no configuration errors, it tries to connect usingconnectToHost(_:port:tlsOptions:)
and passes parameters ontorequest(method:url:headers:body:)
.func setHttpProxy(host: String, port: Int32
) Sets the proxy server for HTTP requests.
func setHttpsProxy(host: String, port: Int32
) Sets the proxy server for HTTPS requests.
func setTlsOptions(clientOptions: TLSOptions?
) Sets the
TLSOptions
to be used when connecting to an HTTPS server. Seeclient(trustedChain:commonNameOverride:)
.