-
Notifications
You must be signed in to change notification settings - Fork 14
/
cookies.R
105 lines (78 loc) · 3.44 KB
/
cookies.R
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
# Seems to be that we are losing the finalizer.
# If we set writefunction to R_internalWriteTest, and set no
# parameters. Things are okay
#
# The problem is in the dynCurlReader().
# Even if we change the update() function in dynCurlReader
# to just return, we still have this problem.
#
library(RCurl)
site <- "http://chr.tx0.org/arch/ml/r/cookie-20101114.cgi"
cookie_1= "cookie1"
# Should work!
h = getCurlHandle(cookiejar = "-", cookiefile = "")
a = postForm(site, par = "cookie1", curl = h, style = "POST")
rm(h); gc(); gc()
h = getCurlHandle(cookiejar = "-", cookiefile = "")
a = getURLContent(site, curl = h)
rm(h) ; gc()
# not okay. But it is if we just return from the update.
h = getCurlHandle(cookiejar = "-", cookiefile = "")
w = dynCurlReader(h)
a = getURLContent(site, curl = h, header = w) # writefunction = w$update)
rm(h, w) ; gc()
# but if we let getURLContent() use the default value for header we don't get the freeing
h = getCurlHandle(cookiejar = "-", cookiefile = "")
a = getURLContent(site, curl = h)
rm(h) ; gc()
# Fine
h = getCurlHandle(cookiejar = "-", cookiefile = "")
w = dynCurlReader(h)
a = getURL(site, curl = h, write = w$update)
rm(h, w) ; gc()
# This works, but the getURLContent() doesn't.
h = getCurlHandle(cookiejar = "-", cookiefile = "")
a = getURL(site, curl = h)
rm(h) ; gc()
h = getCurlHandle(cookiejar = "/tmp/mycookies", cookiefile = "")
a = postForm(site, par = "cookie1", curl = h, style = "POST")
rm(h); gc(); gc()
# HTTPPOST style
h = getCurlHandle(cookiejar = "/tmp/mycookies", cookiefile = "")
a = postForm(site, par = "cookie1", curl = h)
rm(h); gc(); gc()
h = getCurlHandle(cookiejar = "/tmp/mycookies", cookiefile = "")
curlPerform(url = site, postfields = "", curl = curl)
# Change the write function to a C routine and send no parameters
h = getCurlHandle(cookiejar = "/tmp/mycookies", cookiefile = "")
a = postForm(site, curl = h, style = "POST", .opts = list(writefunction = getNativeSymbolInfo("R_internalWriteTest")$address))
rm(h); gc(); gc()
# Adding the parameter still works. So it is the writefunction.
h = getCurlHandle(cookiejar = "/tmp/mycookies", cookiefile = "")
a = postForm(site, curl = h, par = "cookie1", style = "POST", .opts = list(writefunction = getNativeSymbolInfo("R_internalWriteTest")$address))
rm(h); gc(); gc()
# So let's try a regular write function. And that still works. So it is our default writefunction for postForm
w = basicTextGatherer()
h = getCurlHandle(cookiejar = "/tmp/mycookies1", cookiefile = "")
a = postForm(site, curl = h, par = "cookie1", style = "POST", .opts = list(writefunction = w$update))
rm(h); gc(); gc()
h = getCurlHandle(cookiejar = "/tmp/mycookies1", cookiefile = "")
w = dynCurlReader(h, verbose = TRUE)
a = postForm(site, curl = h, par = "cookie1", style = "POST", .opts = list(writefunction = w$update))
rm(h); gc(); gc()
files = sprintf("/tmp/k%d", 1:100)
sapply(files,
function(f) {
h = getCurlHandle(cookiejar = f, cookiefile = "")
w = dynCurlReader(h, verbose = TRUE)
a = postForm(site, curl = h, par = "cookie1", style = "POST", .opts = list(writefunction = w$update))
rm(h); gc()
})
h = getCurlHandle(cookiejar = "-", cookiefile = "")
w = dynCurlReader(h, verbose = TRUE)
a = postForm(site, curl = h, par = "cookie1", style = "POST", .opts = list(writefunction = w$update))
rm(h); invisible(gc())
h = getCurlHandle(cookiejar = "/tmp/mycookies1", cookiefile = "")
a = getURL(site, curl = h)
rm(h)
gc(); gc()