Debian Codegraph @

man/handle.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/handle.R
3 \name{handle}
4 \alias{handle}
5 \alias{new_handle}
6 \alias{handle_setopt}
7 \alias{handle_setheaders}
8 \alias{handle_getheaders}
9 \alias{handle_setform}
10 \alias{handle_reset}
11 \title{Create and configure a curl handle}
12 \usage{
13 new_handle(...)
14
15 handle_setopt(handle, ..., .list = list())
16
17 handle_setheaders(handle, ..., .list = list())
18
19 handle_getheaders(handle)
20
21 handle_setform(handle, ..., .list = list())
22
23 handle_reset(handle)
24 }
25 \arguments{
26 \item{...}{named options / headers to be set in the handle.
27 To send a file, see \code{\link[=form_file]{form_file()}}. To list all allowed options,
28 see \code{\link[=curl_options]{curl_options()}}}
29
30 \item{handle}{Handle to modify}
31
32 \item{.list}{A named list of options. This is useful if you've created
33 a list of options elsewhere, avoiding the use of \code{do.call()}.}
34 }
35 \value{
36 A handle object (external pointer to the underlying curl handle).
37 All functions modify the handle in place but also return the handle
38 so you can create a pipeline of operations.
39 }
40 \description{
41 Handles are the work horses of libcurl. A handle is used to configure a
42 request with custom options, headers and payload. Once the handle has been
43 set up, it can be passed to any of the download functions such as \code{\link[=curl]{curl()}}
44 ,\code{\link[=curl_download]{curl_download()}} or \code{\link[=curl_fetch_memory]{curl_fetch_memory()}}. The handle will maintain
45 state in between requests, including keep-alive connections, cookies and
46 settings.
47 }
48 \details{
49 Use \code{new_handle()} to create a new clean curl handle that can be
50 configured with custom options and headers. Note that \code{handle_setopt}
51 appends or overrides options in the handle, whereas \code{handle_setheaders}
52 replaces the entire set of headers with the new ones. The \code{handle_reset}
53 function resets only options/headers/forms in the handle. It does not affect
54 active connections, cookies or response data from previous requests. The safest
55 way to perform multiple independent requests is by using a separate handle for
56 each request. There is very little performance overhead in creating handles.
57
58 The \link{handle_setform} function is used to perform a \code{multipart/form-data} HTTP
59 POST request (a.k.a. posting a form). The form fields can be specified as
60 strings, raw vectors (for binary data), or \link{form_file} and \link{form_data} for
61 upload elements. See the examples.
62 }
63 \examples{
64 h <- new_handle()
65 handle_setopt(h, customrequest = "PUT")
66 handle_setform(h, a = "1", b = "2")
67 r <- curl_fetch_memory("https://hb.cran.dev/put", h)
68 cat(rawToChar(r$content))
69
70 # Or use the list form
71 h <- new_handle()
72 handle_setopt(h, .list = list(customrequest = "PUT"))
73 handle_setform(h, .list = list(a = "1", b = "2"))
74 r <- curl_fetch_memory("https://hb.cran.dev/put", h)
75 cat(rawToChar(r$content))
76
77 # Posting multipart forms
78 h <- new_handle()
79 handle_setform(h,
80 foo = "blabla",
81 bar = charToRaw("boeboe"),
82 iris = form_data(serialize(iris, NULL), "application/rda"),
83 description = form_file(system.file("DESCRIPTION")),
84 logo = form_file(file.path(R.home('doc'), "html/logo.jpg"), "image/jpeg")
85 )
86 req <- curl_fetch_memory("https://hb.cran.dev/post", handle = h)
87 }
88 \seealso{
89 Other handles:
90 \code{\link[=handle_cookies]{handle_cookies()}}
91 }
92 \concept{handles}