|
1 local Promise = require "prosody.util.promise".Promise; |
|
2 |
|
3 local record sslctx -- from LuaSec |
|
4 end |
|
5 |
|
6 local record lib |
|
7 |
|
8 enum http_method |
|
9 "GET" |
|
10 "HEAD" |
|
11 "POST" |
|
12 "PUT" |
|
13 "OPTIONS" |
|
14 "DELETE" |
|
15 -- etc? |
|
16 end |
|
17 |
|
18 record http_client_options |
|
19 sslctx : sslctx |
|
20 end |
|
21 |
|
22 record http_options |
|
23 id : string |
|
24 onlystatus : boolean |
|
25 body : string |
|
26 method : http_method |
|
27 headers : { string : string } |
|
28 insecure : boolean |
|
29 suppress_errors : boolean |
|
30 streaming_handler : function |
|
31 suppress_url : boolean |
|
32 sslctx : sslctx |
|
33 end |
|
34 |
|
35 record http_request |
|
36 host : string |
|
37 port : string |
|
38 enum scheme |
|
39 "http" |
|
40 "https" |
|
41 end |
|
42 scheme : scheme |
|
43 url : string |
|
44 userinfo : string |
|
45 path : string |
|
46 |
|
47 method : http_method |
|
48 headers : { string : string } |
|
49 |
|
50 insecure : boolean |
|
51 suppress_errors : boolean |
|
52 streaming_handler : function |
|
53 http : http_client |
|
54 time : integer |
|
55 id : string |
|
56 callback : http_callback |
|
57 end |
|
58 |
|
59 record http_response |
|
60 end |
|
61 |
|
62 type http_callback = function (string, number, http_response, http_request) |
|
63 |
|
64 record http_client |
|
65 options : http_client_options |
|
66 request : function (http_client, string, http_options, http_callback) |
|
67 end |
|
68 |
|
69 request : function (string, http_options, http_callback) : Promise, string |
|
70 default : http_client |
|
71 new : function (http_client_options) : http_client |
|
72 events : table |
|
73 -- COMPAT |
|
74 urlencode : function (string) : string |
|
75 urldecode : function (string) : string |
|
76 formencode : function ({ string : string }) : string |
|
77 formdecode : function (string) : { string : string } |
|
78 destroy_request : function (http_request) |
|
79 |
|
80 enum available_features |
|
81 "sni" |
|
82 end |
|
83 features : { available_features : boolean } |
|
84 end |
|
85 |
|
86 return lib |