File: vmod_curl.rst

package info (click to toggle)
libvmod-curl 0.0~git20250603-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 224 kB
  • sloc: ansic: 577; sh: 66; makefile: 42
file content (367 lines) | stat: -rw-r--r-- 7,169 bytes parent folder | download
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
=========
vmod_curl
=========

-------------------
Varnish cURL Module
-------------------

SYNOPSIS
========

import curl;

DESCRIPTION
===========

Varnish Module that provides cURL bindings for Varnish so you can use
Varnish as an HTTP client and fetch headers and bodies from backends.

FUNCTIONS
=========

get
---

Prototype
        ::

                get(STRING)
Return value
        VOID
Description
        Performs a GET request to the given URL.  A deprecated alias
        for this function is `fetch`.
Example
        ::

                curl.get("http://example.com/test");
                curl.free();

head
----

Prototype
        ::

                head(STRING)
Return value
        VOID
Description
        Performs a HEAD request to the given URL.
Example
        ::

                curl.head("http://example.com/test");
                curl.free();

post
----

Prototype
        ::

                post(STRING, STRING)
Return value
        VOID
Description
        Performs a POST request to the given URL.  The second
        parameter are the POST parameters.
Example
        ::

                curl.post("http://example.com/test", "a=b");
                curl.free();

header
------

Prototype
        ::

                header(STRING)
Return value
        STRING
Description
        Returns the header named in the first argument.
Example
        ::

                curl.get("http://example.com/test");
                if (curl.header("X-Foo") == "bar") {
                    ...
                }
                curl.free();

free
----

Prototype
        ::

                free()
Return value
        VOID
Description
        Free the memory used by headers.
        Not needed, will be handled automatically if it's not called.

status
------

Prototype
        ::

                status()
Return value
        INT
Description
        Returns the HTTP status code.
Example
        ::

                curl.get("http://example.com/test");
                if (curl.status() == 404) {
                    ...
                }
                curl.free();

error
-----

Prototype
        ::

                error()
Return value
        STRING
Description
        Returns the HTTP error.

body
----

Prototype
        ::

                body()
Return value
        STRING
Description
        Returns the HTTP body content.

set_timeout
-----------

Prototype
        ::

                set_timeout(INT)
Return value
        VOID
Description
        Sets the CURLOPT_TIMEOUT_MS option to the value of the first argument.

set_connect_timeout
-------------------

Prototype
        ::

                set_connect_timeout(INT)
Return value
        VOID
Description
        Sets the CURLOPT_CONNECTTIMEOUT_MS option to the value of the first argument.

set_ssl_verify_peer
-------------------

Prototype
        ::

                set_ssl_verify_peer(INT)
Return value
        VOID
Description
        Sets the CURLOPT_SSL_VERIFYPEER option to either 0L or 1L, depending on the boolean value of the first argument.

set_ssl_verify_host
-------------------

Prototype
        ::

                set_ssl_verify_host(INT)
Return value
        VOID
Description
        Sets the CURLOPT_SSL_VERIFYHOST option to either 0L or 1L, depending on the boolean value of the first argument.

set_ssl_cafile
--------------

Prototype
        ::

                set_ssl_cafile(STRING)
Return value
        VOID
Description
        Sets the CURLOPT_CAINFO option to the value of the first argument.

set_ssl_capath
--------------

Prototype
        ::

                set_ssl_capath(STRING)
Return value
        VOID
Description
        Sets the CURLOPT_CAPATH option to the value of the first argument.

header_add
----------

Prototype
        ::

                header_add(STRING)
Return value
        VOID
Description
        Adds a custom request header.
        If you add a header that is otherwise generated and used by libcurl
        internally, your added one will be used instead. If you add a header
        with no content as in "Accept:" (no data on the right side of the
        colon), the internally used header will get disabled. Thus, using this
        option you can add new headers, replace internal headers and remove
        internal headers. To add a header with no content, make the content be
        two quotes: ""
Example
        ::

                // copy Host: header from request
                curl.header_add("Host: " + req.http.Host);
                // disable Accept header generated by libcurl
                curl.header_add("Accept:");
                // add X-curl-Request header with no content
                curl.header_add("X-curl-Request: " + curl.unescape("%22%22"));
                // alternative using long string syntax
                curl.header_add({"X-curl-Request: """});

header_add_all
--------------

Prototype
        ::

                header_add_all()
Return value
        VOID
Description
        Adds all headers in the req object to the request.
        If used from a backend thread, the bereq object is used.
        Can be used in combination with header_add() and header_remove().
        The rules in header_add() apply to header_add_all().
Example
        ::

                // copy all headers from the req object in context
                curl.header_add_all();

header_remove
-------------

Prototype
        ::

                header_remove(STRING)
Return value
        VOID
Description
        Removes all custom request header fields matching the given header name.
        Only headers added by header_add() can be removed. To disable headers
        generated internally by libcurl *add* the header with no content.
Example
        ::

                curl.header_remove("Host");

escape
------

Prototype
        ::

                escape(STRING)
Return value
        STRING
Description
        URL encodes the given string.

unescape
--------

Prototype
        ::

                unescape(STRING)
Return value
        STRING
Description
        URL decodes the given string.

set_proxy
---------

Prototype
        ::

                set_proxy(STRING)
Return value
        VOID
Description
        Set the proxy to use.  A deprecated alias for this function is `proxy`.
Example
        ::

                curl.set_proxy("http://user:secret@some.server.dom:8080/");

set_method
----------

Prototype
        ::

                set_method(STRING)
Return value
        VOID
Description
        Set a custom string for this request.
        This doesn't actually change how libcurl behaves or acts in
        regards to the particular request method, it will only change
        the actual string sent in the request.
Example
        ::

                curl.set_method("PURGE");
                curl.head("http://example.com/test");

BUGS
====

None.

COPYRIGHT
=========

Development of this VMOD has been sponsored by the Norwegian company
Aspiro Music AS for usage on their WiMP music streaming service.

This document is licensed under the same license as the
libvmod-curl project. See LICENSE for details.

* Copyright (c) 2011-2014 Varnish Software