1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2013 Matthieu Lucas <lucasmatthieu@gmail.com>
4 # Copyright 2013 Alexis Laferrière <alexis.laf@xymus.net>
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
23 redef fun body_callback
(line
: String) do end
26 fun error_manager
(err
: CURLCode) do if not err
.is_ok
then print err
28 var url
= "http://example.org/"
30 var curl
= new NativeCurl.easy_init
31 if not curl
.is_init
then print
"failed init"
34 error
= curl
.easy_setopt
(new CURLOption.url
, url
)
37 # Activate for advanced debugging
38 #error = curl.easy_setopt(new CURLOption.verbose, 1)
41 var cbManager
= new CallbackManager
42 error
= curl
.register_callback_body
(cbManager
)
45 error
= curl
.easy_perform
49 var info
= curl
.easy_getinfo_long
(new CURLInfoLong.header_size
)
50 assert infoResp
:info
!= null
52 info
= curl
.easy_getinfo_long
(new CURLInfoLong.response_code
)
53 assert infoResp
:info
!= null
55 info
= curl
.easy_getinfo_long
(new CURLInfoLong.http_connectcode
)
56 assert infoResp
:info
!= null
58 info
= curl
.easy_getinfo_long
(new CURLInfoLong.filetime
)
59 assert infoResp
:info
!= null
61 info
= curl
.easy_getinfo_long
(new CURLInfoLong.redirect_count
)
62 assert infoResp
:info
!= null
64 info
= curl
.easy_getinfo_long
(new CURLInfoLong.request_size
)
65 assert infoResp
:info
!= null
67 info
= curl
.easy_getinfo_long
(new CURLInfoLong.ssl_verifyresult
)
68 assert infoResp
:info
!= null
70 info
= curl
.easy_getinfo_long
(new CURLInfoLong.httpauth_avail
)
71 assert infoResp
:info
!= null
73 info
= curl
.easy_getinfo_long
(new CURLInfoLong.proxyauth_avail
)
74 assert infoResp
:info
!= null
76 info
= curl
.easy_getinfo_long
(new CURLInfoLong.os_errno
)
77 assert infoResp
:info
!= null
79 info
= curl
.easy_getinfo_long
(new CURLInfoLong.primary_port
)
80 assert infoResp
:info
!= null
82 info
= curl
.easy_getinfo_long
(new CURLInfoLong.num_connects
)
83 assert infoResp
:info
!= null
85 info
= curl
.easy_getinfo_long
(new CURLInfoLong.local_port
)
86 assert infoResp
:info
!= null
88 info
= curl
.easy_getinfo_long
(new CURLInfoLong.lastsocket
)
89 assert infoResp
:info
!= null
91 info
= curl
.easy_getinfo_long
(new CURLInfoLong.condition_unmet
)
92 assert infoResp
:info
!= null
94 info
= curl
.easy_getinfo_long
(new CURLInfoLong.rtsp_client_cseq
)
95 assert infoResp
:info
!= null
97 info
= curl
.easy_getinfo_long
(new CURLInfoLong.rtsp_server_cseq
)
98 assert infoResp
:info
!= null
100 info
= curl
.easy_getinfo_long
(new CURLInfoLong.rtsp_cseq_self
)
101 assert infoResp
:info
!= null
104 var infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.total_time
)
105 assert infoResp
:infoDouble
!= null
107 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.namelookup_time
)
108 assert infoResp
:infoDouble
!= null
110 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.connect_time
)
111 assert infoResp
:infoDouble
!= null
113 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.appconnect_time
)
114 assert infoResp
:infoDouble
!= null
116 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.pretransfer_time
)
117 assert infoResp
:infoDouble
!= null
119 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.starttransfer_time
)
120 assert infoResp
:infoDouble
!= null
122 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.redirect_time
)
123 assert infoResp
:infoDouble
!= null
125 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.size_upload
)
126 assert infoResp
:infoDouble
!= null
128 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.size_download
)
129 assert infoResp
:infoDouble
!= null
131 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.speed_download
)
132 assert infoResp
:infoDouble
!= null
134 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.speed_upload
)
135 assert infoResp
:infoDouble
!= null
137 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.content_length_download
)
138 assert infoResp
:infoDouble
!= null
140 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.content_length_upload
)
141 assert infoResp
:infoDouble
!= null
144 var infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.content_type
)
145 assert infoResp
:infoStr
!= null
147 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.effective_url
)
148 assert infoResp
:infoStr
!= null
150 # follow_location not set, so returns null
151 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.redirect_url
)
152 assert infoStr
== null
154 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.primary_ip
)
155 assert infoResp
:infoStr
!= null
157 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.local_ip
)
158 assert infoResp
:infoStr
!= null
160 # Not connecting to FTP so `null`
161 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.ftp_entry_path
)
162 assert infoStr
== null
164 # opt private not set nor implemented, so returns null
165 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.private_data
)
166 assert infoStr
== null
168 # Not an RTSP connection so `null`
169 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.rtsp_session_id
)
170 assert infoStr
== null
173 var infoList
= curl
.easy_getinfo_slist
(new CURLInfoSList.ssl_engines
)
174 assert infoResp
:infoList
!= null
176 infoList
= curl
.easy_getinfo_slist
(new CURLInfoSList.cookielist
)
177 assert infoResp
:infoList
!= null
180 var mailList
= new CURLSList.with_str
("titi")
181 mailList
.append
("toto")
182 mailList
.append
("toto2")
183 mailList
.append
("toto3")
184 mailList
.append
("toto4")
185 mailList
.append
("toto9")
186 if mailList
.is_init
then
187 var content
= mailList
.to_a
188 print
"CURLSList to array - content: {content.to_s}"
189 print
"CURLSList to array - length: {content.length.to_s}"
192 print
"CURLSList to array: CURLSList wrong init"
195 # CURLSList from Array
196 var mailRecipientsArray
= new Array[String]
197 mailRecipientsArray
.add
("tata")
198 mailRecipientsArray
.add
("tata2")
199 var mailRecipientsList
: CURLSList = mailRecipientsArray
.to_curlslist
200 if mailRecipientsList
.is_init
then
201 print
"Array to CURLSList - content: {mailRecipientsList.to_a.to_s}"
202 print
"Array to CURLSList - length: {mailRecipientsList.to_a.length.to_s}"
203 mailRecipientsList
.destroy
205 print
"CURLSList to array: CURLSList wrong init"
209 var hashMapRefined
= new HeaderMap
210 hashMapRefined
["hello"] = "toto"
211 hashMapRefined
["hello"] = "tata"
212 hashMapRefined
["allo"] = "foo"
213 print hashMapRefined
.to_url_encoded
(sys
.curl
)