aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/ecore_con/efl_net_dialer_http.eo
blob: af2a3d8f0c83113a7175160900f63c602ed3562d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
import efl_net_http_types;

enum Efl.Net.Dialer.Http.Primary_Mode {
    [[Primary HTTP mode]]
    auto, [[HTTP auto mode]]
    download, [[HTTP download mode]]
    upload, [[HTTP upload mode]]
}

class Efl.Net.Dialer.Http (Efl.Loop_User, Efl.Net.Dialer, Efl.Io.Sizer) {
    [[HTTP Dialer (Client).

      The effective URL in use, if @.allow_redirects is $true will be
      available as @Efl.Net.Socket.address_remote. The
      @Efl.Net.Socket.address_local is an IP:PORT pair.

      The dialer can do bi-directional information exchange. It can
      also do a PUT and upload a file, or GET and download one. Anoter
      case is to do a POST with some form values, including a file,
      and retrieve its headers and response body. To make usage more
      streamlined, choose your primary interest with @.primary_mode
      then get some properties such as @Efl.Io.Sizer.size to report or
      use what matters to your use case.

      If @.allow_redirects is $true, multiple "connected" and
      "resolved" signals will be dispatched, one for each
      connection. Then @.response_status and @.response_headers_get
      will keep changing. Using @.response_headers_all_get one can see
      the whole history of headers and connections.

      To enable debugging use EINA_LOG_LEVELS=ecore_con:4 environment
      variable.

      If the proxy is NULL (default), then the system proxy will be
      used. On UNIX that's the environment variable $http_proxy (or
      '$all_proxy') is used if the given address doesn't match
      $no_proxy patterns. To disable proxy use an empty string. If
      provided proxy must be one of the protocols:

       - http://username:password\@proxyserver:port
       - http://username\@proxyserver:port
       - http://proxyserver:port
       - http://proxyserver  (default port 1080)
       - socks5://username:password\@proxyserver:port (SOCKSv5)
       - socks5h://username\@proxyserver:port (let socks server to resolve domain)
       - socks5://proxyserver:port
       - socks5://proxyserver (default port 1080)
       - socks4a://proxyserver:port (SOCKSv4 and let socks server to resolve domain)
       - socks4://proxyserver:port (SOCKSv4)

      @since 1.19
    ]]
    methods {
        @property method {
            [[The HTTP method to use.

              A string representing the HTTP method to use, such as
              GET, POST, HEAD, PUT, DELETE...

              This should be set before dialing.
            ]]
            get { }
            set { }
            values {
                method: string; [[HTTP method]]
            }
        }

        @property primary_mode {
            [[Is this request primarily a download or upload?

              This property will change the behavior of @Efl.Io.Sizer:

               - If @Efl.Net.Dialer.Http.Primary_Mode.auto, then
                 @Efl.Net.Dialer.Http.Primary_Mode.download or
                 @Efl.Net.Dialer.Http.Primary_Mode.upload will be
                 choosen based on the @.method: if "PUT", then it's
                 upload, otherwise it's download.

               - If @Efl.Net.Dialer.Http.Primary_Mode.upload, applying
                 a new size with @Efl.Io.Sizer.resize or
                 @Efl.Io.Sizer.size.set will specify the
                 "Content-Length" to upload. If no size is previously
                 set, then the upload will happen in
                 "Transfer-encoding: chunked".

               - If @Efl.Net.Dialer.Http.Primary_Mode.download, then
                 @Efl.Io.Sizer.size.get will report the
                 "Content-Length" provided by the server, if any.

               If is worth to mention that one can provide and
               retrieve these values using @.request_headers_get (to
               send) and @.response_headers_get (what was received),
               as well as using the specific properties
               @.request_content_length (upload) and
               @.response_content_length (download).
            ]]
            get {
                [[The effective primary mode.

                  This will return one of
                  @Efl.Net.Dialer.Http.Primary_Mode.download or
                  @Efl.Net.Dialer.Http.Primary_Mode.upload. If "auto"
                  was set (the default), then it will pick the best
                  based on the @.method in use.
                ]]
            }
            set { }
            values {
                primary_mode: Efl.Net.Dialer.Http.Primary_Mode; [[Primary HTTP mode]]
            }
        }

        @property user_agent {
            [[The User-Agent to specify.

              This should be set before dialing.
            ]]
            get { }
            set { }
            values {
                ser_agent: string; [[User-agent]]
            }
        }

        @property http_version {
            [[The HTTP version to use.

              This should be set before dialing.

              Once connected, it will change to the actual connection
              HTTP version, so check after "connected" event.
            ]]
            get { }
            set { }
            values {
                http_version: Efl.Net.Http.Version; [[HTTP version]]
            }
        }

        @property authentication {
            [[HTTP authentication to use.

              This should be set before dialing.
            ]]
            get { }
            set { }
            values {
                username: string; [[HTTP authentication username]]
                password: string; [[HTTP authentication password]]
                method: Efl.Net.Http.Authentication_Method @optional; [[Authentication method to use, defaults to @Efl.Net.Http.Authentication_Method.basic]]
                restricted: bool @optional; [[Restrict method]]
            }
        }

        @property allow_redirects {
            [[Allows HTTP redirects to be followed.

              This should be set before dialing.
            ]]
            get { }
            set { }
            values {
                allow_redirects: bool; [[$true if redirects are followed, $false otherwise]]
            }
        }

        request_header_add {
            [[Adds a request header 'key: value'.

              See @.request_headers_clear

              This should be called before dialing.
            ]]
            params {
                @in key: string; [[Request header key]]
                @in value: string; [[Request header value]]
            }
        }

        request_headers_clear {
            [[Clears all request headers.

              See @.request_header_add

              This should be called before dialing.
            ]]
        }

        request_headers_get {
            [[Returns an iterator to the key-value pairs for request headers]]
            return: iterator<Efl.Net.Http.Header> @owned @warn_unused; [[Iterator for request headers]]
        }

        @property request_content_length {
            [["Content-Length:" Header used for uploading/sending.

              To unset use -1
            ]]
            get { }
            set { }
            values {
                length: int64; [[Length value]]
            }
        }

        @property response_content_length {
            [["Content-Length:" Header used for downloading/receiving.

              If unset is -1.
            ]]
            get { }
            set @protected { }
            values {
                length: int64; [[Length value]]
            }
        }

        @property response_content_type {
            [["Content-Type:" Header used for downloading/receiving]]
            get { }
            set @protected { }
            values {
                content_type: string; [[Content type header string]]
            }
        }

        @property response_status {
            [[The HTTP response status of this request.

              It will be 0 if not connected, otherwise will be what is
              returned by the server, such as.

              See https://en.wikipedia.org/wiki/List_of_HTTP_status_codes

              This will be usable after "connected" event is dispatched.
            ]]
            get { }
            values {
                status_code: Efl.Net.Http.Status; [[HTTP status]]
            }
        }

        response_headers_get {
            [[Returns an iterator to the key-value pairs for the last response headers.

              Since multiple requests can happen if @.allow_redirects
              is true, then all headers will be accumulated. This
              method returns only the headers for the last request.

              To know all the headers, check @.response_headers_all_get.

              This will be usable after "headers,done" event is dispatched.
            ]]
            return: iterator<Efl.Net.Http.Header> @owned @warn_unused; [[Iterator for response headers]]
        }

        response_headers_all_get {
            [[Returns an iterator to the key-value pairs for all response headers.

              Since multiple requests can happen if @.allow_redirects
              is true, then all headers will be accumulated. To know
              when new request is started, check for headers with keys
              being NULL, the value will be the "HTTP/VERSION RESPONSE"
              string received from the host, such as:

                - key=NULL, value="HTTP/1.1 302 Found"
                - key="Location", value="http://someredirect.com"
                - key=NULL, value="HTTP/1.1 200 Ok"
                - key="Content-Type", value="text/html"

              Which mean the original request had a redirect to
              http://someredirect.com.

              To receive an iterator to just the last request, use
              @.response_headers_get

              This will be usable after "headers,done" event is dispatched.
            ]]
            return: iterator<Efl.Net.Http.Header> @owned @warn_unused; [[Iterator for all response headers]]
        }

        response_headers_clear {
            [[Saves some memory by disposing the received headers]]
        }

        @property progress_download {
            [[How many bytes were downloaded and how much was expected.]]
            get { }
            values {
                downloaded: uint64 @optional; [[Downloaded bytes so far]]
                total: uint64 @optional; [[Download total in bytes, 0 if unknown]]
            }
        }

        @property progress_upload {
            [[How many bytes were uploaded and how much was expected.]]
            get { }
            values {
                uploaded: uint64 @optional; [[Uploaded bytes so far]]
                total: uint64 @optional; [[Upload total in bytes, 0 if unknown]]
            }
        }

        @property cookie_jar {
            [[This property sets the filename where to read and write cookies.

              By setting a file to load and persist cookies to, the
              internal cookie system will be activated, automatically
              handling HTTP headers such as 'Set-cookie:' and sending
              the appropriate cookies for a server.

              If a new, empty session is to be used, start with an
              empty or non-existent file such as created with
              mkstemp() or tmpfile(). An alternative is to use an
              empty string ("") to keep it in memory.

              If it is desired to start from a pre-existent cookie jar
              but do not want to modify that, first copy that file and
              then pass the new, temporary file.

              Likewise, if it's desired to fill some cookies to the
              system, create a cookie jar and pass its path to this
              property.

              \@note that whenever this property is set, even if to the
              same value, it will flush all cookies to the previously
              set file, then erase all known cookies, then use the new
              file (if any).
            ]]
            get { }
            set { }
            values {
                path: string; [[Path to cookie jar]]
            }
        }

        @property ssl_verify {
            [[If remote peer's SSL certificate should be verified.

              Defaults to both peer and hostname verification (all $true).
            ]]
            values {
                peer: bool; [[If $true, SSL certificate will be verified. If $false, untrusted certificates (including self signed) will be accepted.]]
                hostname: bool; [[If $true, in addition to SSL certificate validation, the server name will be matched to certificate DNS entries]]
            }
        }

        @property ssl_certificate_authority {
            [[Overrides the CA (Certificate Authority) path or directory.

              Defaults to system setup.
            ]]
            values {
                path: string; [[Directory or file path to use for Certificate Authority]]
            }
        }

        @property ssl_certificate_revocation_list {
            [[Defines a CRL (Certificate Revocation List) path to use.]]
            values {
                file: string; [[File path to use for CRL]]
            }
        }

        date_parse @class {
            [[Parses the given string as time in seconds since 1/1/1970.

              This method is useful to parse header values such as
              "Last-Modified".
            ]]
            params {
                str: string; [[String in HTTP text format: Tue, 15 Nov 1994 12:45:26 GMT]]
            }
            return: int64; [[Seconds since 1/1/1970]]
        }

        date_serialize @class {
            [[Serializes the given GMT time in seconds since 1/1/1970.

              The timezone must be GMT (ie: gmtime()).
            ]]
            params {
                epochtime: int64; [[UNIX Epoch time - seconds since 1/1/1970]]
            }
            return: mstring @owned @warn_unused; [[Newly allocated null-terminated string on success or NULL on errors]]
        }
    }

    events {
        headers,done; [[Notifies all headers were parsed and are available.]]
    }

    implements {
        Efl.Object.constructor;
        Efl.Object.destructor;
        Efl.Net.Dialer.dial;
        Efl.Net.Dialer.address_dial { get; set; }
        Efl.Net.Dialer.connected { get; set; }
        Efl.Net.Dialer.proxy { get; set; }
        Efl.Net.Dialer.timeout_dial { get; set; }
        Efl.Net.Socket.address_local { get; set; }
        Efl.Net.Socket.address_remote { get; set; }
        Efl.Io.Reader.read;
        Efl.Io.Reader.can_read { get; set; }
        Efl.Io.Reader.eos { get; set; }
        Efl.Io.Writer.write;
        Efl.Io.Writer.can_write { get; set; }
        Efl.Io.Closer.close;
        Efl.Io.Closer.closed { get; }
        Efl.Io.Closer.close_on_exec { get; set; }
        Efl.Io.Closer.close_on_destructor { get; set; }
        Efl.Io.Sizer.resize;
        Efl.Io.Sizer.size { get; }
    }
}