Instance Methodmigueldeicaza.swiftgodot 0.45.0SwiftGodot
request(url:customHeaders:method:requestData:)
Creates request on the underlying HTTPClient
. If there is no configuration errors, it tries to connect using connectToHost(_:port:tlsOptions:)
and passes parameters onto request(method:url:headers:body:)
.
final func request(url: String, customHeaders: PackedStringArray = PackedStringArray(), method: HTTPClient.Method = .get, requestData: String = "") -> GodotError
Returns ok
if request is successfully created. (Does not imply that the server has responded), errUnconfigured
if not in the tree, errBusy
if still processing previous request, errInvalidParameter
if given string is not a valid URL format, or errCantConnect
if not using thread and the HTTPClient
cannot connect to host.
Other members in extension
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 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:)
.