GetRemoteRequestInfo: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(initial)
 
(Remove obsolete Requirements section)
 
(10 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Server client function}}
{{Server client function}}
__NOTOC__
__NOTOC__
{{New feature/item|3.0158|1.5.7|20307|
Gets informations of an [[FetchRemote|fetchRemote]] or [[CallRemote|callRemote]] request info.
Gets informations of an [[FetchRemote|fetchRemote]] or [[CallRemote|callRemote]] request info.
 
}}
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool GetRemoteRequestInfo ( request theRequest )
table getRemoteRequestInfo ( request theRequest [, int postDataLength = 0 [, bool includeHeaders = false ] ] )
</syntaxhighlight>
</syntaxhighlight>


===Required Arguments===
===Required Arguments===
* '''theRequest''': the element returned from [[FetchRemote|fetchRemote]] or [[CallRemote|callRemote]]
* '''theRequest''': returned from [[FetchRemote|fetchRemote]], [[CallRemote|callRemote]] or [[GetRemoteRequests|getRemoteRequests]]


==Returns==
==Returns==
Returns a table when valid, false otherwise
Returns a table when valid, false otherwise
The table contains:
*'''bytesReceived:''' A number specifying the amount of data received so far. Zero means the download is queued
*'''bytesTotal:''' A number specifying the final download size. Will be zero if the remote HTTP server has not set the 'Content-Length' header
*'''currentAttempt:''' A number specifying the current connection attempt
*'''type:''' A string specifying either "fetch" or "call"
*'''url:''' A string specifying the URL
*'''resource:''' The resource which started the request, or false if the resource has since been stopped/restarted
*'''queue:''' A string specifying the queue name
*'''method:''' A string specifying the HTTP method. e.g. "GET" or "POST"
*'''connectionAttempts:''' A number specifying max number connection attempts as declared in the fetchRemote call
*'''connectionTimeout:''' A number specifying connection attempt timeout as declared in the fetchRemote call
*'''postData:''' A string containing the request post data as declared in the fetchRemote call
*'''headers:''' A table containing the request HTTP headers as declared in the fetchRemote call


==Example==
==Example==
<section name="Server" class="server" show="true">
<section name="Server" class="server" show="true">
This example gets infos about all pending requests
This example gets infos about all pending requests and prints them in debugscript
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function CMD_requestInfo(player, _, resourceName)
function CMD_requestInfo(player, _, resourceName)
Line 38: Line 52:
         end
         end
     end
     end
end
addCommandHandler("requestinfo", CMD_requestInfo)
end
end


Line 47: Line 58:
</section>
</section>
<section name="Client" class="client" show="true">
<section name="Client" class="client" show="true">
This example gets infos about all pending requests
This example gets infos about all pending requests and prints them in debugscript
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function CMD_requestInfo(player, _, resourceName)
function CMD_requestInfo(player, _, resourceName)
Line 74: Line 85:
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>
{{Requirements|1.5.7-9.20307|1.5.7-9.20307}}


==See Also==
==See Also==
{{Resource functions}}
{{Resource functions}}

Latest revision as of 17:17, 7 November 2024

Gets informations of an fetchRemote or callRemote request info.

Syntax

table getRemoteRequestInfo ( request theRequest [, int postDataLength = 0 [, bool includeHeaders = false ] ] )

Required Arguments

Returns

Returns a table when valid, false otherwise The table contains:

  • bytesReceived: A number specifying the amount of data received so far. Zero means the download is queued
  • bytesTotal: A number specifying the final download size. Will be zero if the remote HTTP server has not set the 'Content-Length' header
  • currentAttempt: A number specifying the current connection attempt
  • type: A string specifying either "fetch" or "call"
  • url: A string specifying the URL
  • resource: The resource which started the request, or false if the resource has since been stopped/restarted
  • queue: A string specifying the queue name
  • method: A string specifying the HTTP method. e.g. "GET" or "POST"
  • connectionAttempts: A number specifying max number connection attempts as declared in the fetchRemote call
  • connectionTimeout: A number specifying connection attempt timeout as declared in the fetchRemote call
  • postData: A string containing the request post data as declared in the fetchRemote call
  • headers: A table containing the request HTTP headers as declared in the fetchRemote call

Example

Click to collapse [-]
Server

This example gets infos about all pending requests and prints them in debugscript

function CMD_requestInfo(player, _, resourceName)
    local res = resourceName and getResourceFromName(resourceName) or not resourceName and nil
	
    if(res == false) then
        outputServerLog("There is no resource named '" .. resourceName .. "'")
        return
    elseif(res and getResourceState(res) ~= "running") then
        outputServerLog("The provided resource '" .. resourceName .. "' is not running")
        return
    end
	
    local requests = getRemoteRequests(res)
	
    for _, request in ipairs(requests) do
        local requestInfo = getRemoteRequestInfo(request)
		
        if(requestInfo) then
            iprint(requestInfo)
        end
    end
end

addCommandHandler("requestinfo", CMD_requestInfo)
Click to collapse [-]
Client

This example gets infos about all pending requests and prints them in debugscript

function CMD_requestInfo(player, _, resourceName)
    local res = resourceName and getResourceFromName(resourceName) or not resourceName and nil
	
    if(res == false) then
        outputChatBox("There is no resource named '" .. resourceName .. "'")
        return
    elseif(res and getResourceState(res) ~= "running") then
        outputChatBox("The provided resource '" .. resourceName .. "' is not running")
        return
    end
	
    local requests = getRemoteRequests(res)
	
    for _, request in ipairs(requests) do
        local requestInfo = getRemoteRequestInfo(request)
		
        if(requestInfo) then
            iprint(requestInfo)
        end
    end
end

addCommandHandler("requestinfo", CMD_requestInfo)

See Also