@@ -34,7 +34,7 @@ In libcurl, you create a handle using `curl_easy_init
34
34
<https://curl.se/libcurl/c/curl_easy_init.html> `_. In the Open Dylan
35
35
wrapper, you create an object of the :class: `<curl-easy> ` class.
36
36
37
- .. code-block :: c
37
+ .. code-block :: C
38
38
:caption: C example
39
39
40
40
CURL *curl = curl_easy_init();
@@ -43,17 +43,23 @@ wrapper, you create an object of the :class:`<curl-easy>` class.
43
43
curl_easy_cleanup(curl);
44
44
}
45
45
46
+ The macro :macro: `with-curl-easy ` handles both initialization and
47
+ automatic cleanup when it is no longer accessible. If initialization
48
+ fails, a :class: `<curl-init-error> ` exception is raised.
49
+
46
50
.. code-block :: dylan
47
51
:caption: Dylan example
48
52
49
- with-curl-easy (curl)
50
- ...
53
+ block ()
54
+ with-curl-easy (curl = make(<curl-easy>))
55
+ // perform request
56
+ // gather information about the request
57
+ end;
58
+ exception (err :: <curl-init-error>)
59
+ format-err("Error initializing curl: %s\n",
60
+ err.curl-error-message)
51
61
end;
52
62
53
- The macro :macro: `with-curl-easy ` handles both initialization and
54
- automatic cleanup when it is no longer accessible. If initialization
55
- fails, a :class: `<curl-init-error> ` exception is raised.
56
-
57
63
Setting Parameters
58
64
^^^^^^^^^^^^^^^^^^
59
65
@@ -87,19 +93,36 @@ handled either immediately at the point of the operation or deferred
87
93
to another method for centralized error handling.
88
94
89
95
.. code-block :: dylan
90
- :caption: In Dylan errors can be captured in a block somewhere .
96
+ :caption: In Dylan errors can be captured in a block.
91
97
92
- with-curl-easy (curl)
93
- curl.curl-url := "https://example.com";
94
- end;
98
+ block ()
99
+ with-curl-easy (curl = make(<curl-easy>))
100
+ curl.curl-url := "https://example.com";
101
+ // perform request
102
+ // gather information
103
+ end;
104
+ exception (err :: <curl-option-error>)
105
+ format-err("Error setting option: %s\n",
106
+ err.curl-error-message)
107
+ end block;
108
+
109
+ If you need to set a lot of options, you can pass them to the
110
+ :macro: `with-curl-easy ` with less verbosity.
95
111
96
- ...
112
+ .. code-block :: dylan
97
113
98
114
block ()
99
- // somewhere in the code an option is incorrect
100
- // and is handled here
115
+ with-curl-easy (curl = make(<curl-easy>),
116
+ url = "https://example.org",
117
+ ssl-verifypeer = #f,
118
+ ssl-verifyhost = 1,
119
+ ca-cache-timeout = 604800)
120
+ // perform request
121
+ // gather information
122
+ end with-curl-easy;
101
123
exception (err :: <curl-option-error>)
102
- format-err("Error setting option: %s\n", err.curl-error-message)
124
+ format-err("Error setting option: %s\n",
125
+ err.curl-error-message)
103
126
end block;
104
127
105
128
Performing the Request
@@ -125,11 +148,12 @@ In Opendylan :func:`curl-perform` raises a
125
148
.. code-block :: dylan
126
149
:caption: Dylan example
127
150
128
- block ()
151
+ block ()
129
152
curl-easy-perform(curl);
130
153
format-out("Request completed successfully.\n")
131
154
exception (err :: <curl-perform-error>)
132
- format-err("Curl failed: %s\n", curl.curl-error-message)
155
+ format-err("Curl failed: %s\n",
156
+ curl.curl-error-message)
133
157
end block;
134
158
135
159
Retrieving Information
@@ -166,11 +190,11 @@ wrapper, you access the information directly using property syntax.
166
190
:caption: Dylan Example
167
191
168
192
block ()
169
- with-curl-easy (curl)
170
- curl.curl- url : = "https://example.com/";
193
+ with-curl-easy (curl = make(<curl>),
194
+ url = "https://example.com/")
171
195
curl-easy-perform(curl);
172
196
format-out("Time: %d", curl.total-time)
173
- end
197
+ end;
174
198
exception (err :: <curl-info-error>)
175
199
format-err("curl easy getinfo failed: %s\n",
176
200
err.curl-error-message)
0 commit comments