| request - a request from HttpRequest |
|
Returns how much of a request's answer has arrived, from 0 to 1. Use it for a download's progress bar: multiply it by the bar's width. It only ever goes up while the answer arrives, and it is 1 once the request has ended with an answer. It relies on the server saying how big the answer will be, which most do for files. When the server doesn't say, HttpProgress stays at 0 until the whole answer is in, and then jumps to 1; on the web, a compressed answer counts as one whose size isn't known. A request that ends without an answer keeps the value it had. For a request that sends a file (HttpRequest's sendFile$), it counts the file going first, on Windows, then the answer: it reaches 0.9 as the last of the file goes, while the server has yet to answer, and still never goes back. See also: HttpRequest, HttpStatus, FreeHttpRequest. |
; HttpProgress Example
; --------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
camera=CreateCamera()
PositionEntity camera,0,0,-3
light=CreateLight()
RotateEntity light,45,45,0
; A 3.7 MB glTF model from the Khronos Group's samples on GitHub
url$="https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Assets/main/Models/DamagedHelmet/glTF-Binary/DamagedHelmet.glb"
file$=SystemProperty("tempdir")+"DamagedHelmet.glb"
; Download it into a file, which appears once the whole answer is in
request=HttpRequest(url,"GET","","",file)
helmet=0
While Not KeyDown(1)
; When the download ends well, load the model it saved
If helmet=0 And HttpStatus(request)=200 Then
helmet=LoadMesh(file)
EndIf
If helmet Then TurnEntity helmet,0,0.5,0
; Arrow keys move the camera
If KeyDown(200) Then MoveEntity camera,0,0,0.1
If KeyDown(208) Then MoveEntity camera,0,0,-0.1
If KeyDown(203) Then TurnEntity camera,0,1,0
If KeyDown(205) Then TurnEntity camera,0,-1,0
RenderWorld
; HttpProgress goes from 0 to 1 as the answer arrives
progress#=HttpProgress(request)
Rect 20,440,600,20,False
Rect 20,440,600*progress,20,True
Text 0,0,"Arrow keys: move camera Esc: exit"
Text 0,20,"HttpProgress(request) = "+progress
If HttpStatus(request)<0 Then Text 0,40,"No answer: "+HttpError(request)
Flip
Wend
; Stop the download if it still runs, and tidy up its file
FreeHttpRequest request
DeleteFile file
End