@@ -2763,33 +2763,61 @@ function SetPlayerChatBubble(amx, player, text, color, dist, exptime)
2763
2763
end
2764
2764
2765
2765
2766
- -- In MTA we can't set the type of the request.
2767
- -- When we add 'data' it becomes POST request.
2768
- -- TODO: arguments "index" and "type" here only for compatibility.
2766
+ -- Now we have all of RESTful types of requests. Our function is better!
2767
+ -- The SAMP documentation said about 'url' - "The URL you want to request. (Without 'http://')"
2768
+ -- I made a check. The state without a protocol is called as 'default'.
2769
+ -- HTTP and HTTPS you can put into URL if you want. It works fine.
2770
+ -- TODO: An "index" argument only for compatibility.
2769
2771
function HTTP (amx , index , type , url , data , callback )
2770
- if type == 3 then
2771
- notImplemented (' HTTP' , ' A HEAD type have not support right now' )
2772
+
2773
+ local protomatch = pregMatch (url ,' ^(\\ w+):\\ /\\ /' )
2774
+ local proto = protomatch [1 ] or ' default'
2775
+ -- if somebody will try to put here ftp:// ssh:// etc...
2776
+ if proto ~= ' http' and proto ~= ' https' and proto ~= ' default' then
2777
+ print (' Current protocol is not supporting' )
2778
+ return 0
2772
2779
end
2773
- local request = fetchRemote (" http://" .. url ,
2774
- function (responseData , error )
2780
+ local typesToText = {
2781
+ ' GET' ,
2782
+ ' POST' ,
2783
+ ' HEAD' ,
2784
+ [- 4 ] = ' PUT' ,
2785
+ [- 5 ] = ' PATCH' ,
2786
+ [- 6 ] = ' DELETE' ,
2787
+ [- 7 ] = ' COPY' ,
2788
+ [- 8 ] = ' OPTIONS' ,
2789
+ [- 9 ] = ' LINK' ,
2790
+ [- 10 ] = ' UNLINK' ,
2791
+ [- 11 ] = ' PURGE' ,
2792
+ [- 12 ] = ' LOCK' ,
2793
+ [- 13 ] = ' UNLOCK' ,
2794
+ [- 14 ] = ' PROPFIND' ,
2795
+ [- 15 ] = ' VIEW'
2796
+ }
2797
+ local sendOptions = {
2798
+ queueName = " amx." .. getResourceName (amx .res ) .. " ." .. amx .name ,
2799
+ postData = data ,
2800
+ method = typesToText [tonumber (type )],
2801
+ }
2802
+ local successRemote = fetchRemote (url , sendOptions ,
2803
+ function (responseData , responseInfo )
2804
+ local error = responseInfo .statusCode
2775
2805
if error == 0 then
2776
2806
procCallInternal (amx , callback , index , 200 , responseData )
2777
- return 1 ;
2778
2807
elseif error >= 1 and error <= 89 then
2779
2808
procCallInternal (amx , callback , index , 3 , responseData )
2780
- return 0 ;
2781
2809
elseif error == 1006 or error == 1005 then
2782
2810
procCallInternal (amx , callback , index , 1 , responseData )
2783
- return 0 ;
2784
2811
elseif error == 1007 then
2785
2812
procCallInternal (amx , callback , index , 5 , responseData )
2786
- return 0 ;
2787
2813
else
2788
2814
procCallInternal (amx , callback , index , error , responseData )
2789
- return 0 ;
2790
2815
end
2791
- end , data , false )
2792
- return 0 ;
2816
+ end )
2817
+ if not successRemote then
2818
+ return 0
2819
+ end
2820
+ return 1
2793
2821
end
2794
2822
2795
2823
function Create3DTextLabel (amx , text , r , g , b , a , x , y , z , dist , vw , los )
0 commit comments