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.
24 redef fun body_callback
(line
: String) do end
27 fun error_manager
(err
: CURLCode) do if not err
.is_ok
then print err
29 var url
= "http://example.org/"
31 var curl
= new CCurl.easy_init
32 if not curl
.is_init
then print
"failed init"
35 error
= curl
.easy_setopt
(new CURLOption.url
, url
)
38 # Activate for advanced debugging
39 #error = curl.easy_setopt(new CURLOption.verbose, 1)
42 var cbManager
= new CallbackManager
43 error
= curl
.register_callback
(cbManager
, new CURLCallbackType.body
)
46 error
= curl
.easy_perform
50 var info
:nullable CURLInfoResponseLong
51 info
= curl
.easy_getinfo_long
(new CURLInfoLong.header_size
)
52 assert infoResp
:info
!= null
54 info
= curl
.easy_getinfo_long
(new CURLInfoLong.response_code
)
55 assert infoResp
:info
!= null
57 info
= curl
.easy_getinfo_long
(new CURLInfoLong.http_connectcode
)
58 assert infoResp
:info
!= null
60 info
= curl
.easy_getinfo_long
(new CURLInfoLong.filetime
)
61 assert infoResp
:info
!= null
63 info
= curl
.easy_getinfo_long
(new CURLInfoLong.redirect_count
)
64 assert infoResp
:info
!= null
66 info
= curl
.easy_getinfo_long
(new CURLInfoLong.request_size
)
67 assert infoResp
:info
!= null
69 info
= curl
.easy_getinfo_long
(new CURLInfoLong.ssl_verifyresult
)
70 assert infoResp
:info
!= null
72 info
= curl
.easy_getinfo_long
(new CURLInfoLong.httpauth_avail
)
73 assert infoResp
:info
!= null
75 info
= curl
.easy_getinfo_long
(new CURLInfoLong.proxyauth_avail
)
76 assert infoResp
:info
!= null
78 info
= curl
.easy_getinfo_long
(new CURLInfoLong.os_errno
)
79 assert infoResp
:info
!= null
81 info
= curl
.easy_getinfo_long
(new CURLInfoLong.primary_port
)
82 assert infoResp
:info
!= null
84 info
= curl
.easy_getinfo_long
(new CURLInfoLong.num_connects
)
85 assert infoResp
:info
!= null
87 info
= curl
.easy_getinfo_long
(new CURLInfoLong.local_port
)
88 assert infoResp
:info
!= null
90 info
= curl
.easy_getinfo_long
(new CURLInfoLong.lastsocket
)
91 assert infoResp
:info
!= null
93 info
= curl
.easy_getinfo_long
(new CURLInfoLong.condition_unmet
)
94 assert infoResp
:info
!= null
96 info
= curl
.easy_getinfo_long
(new CURLInfoLong.rtsp_client_cseq
)
97 assert infoResp
:info
!= null
99 info
= curl
.easy_getinfo_long
(new CURLInfoLong.rtsp_server_cseq
)
100 assert infoResp
:info
!= null
102 info
= curl
.easy_getinfo_long
(new CURLInfoLong.rtsp_cseq_recv
)
103 assert infoResp
:info
!= null
106 var infoDouble
: nullable CURLInfoResponseDouble
107 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.total_time
)
108 assert infoResp
:infoDouble
!= null
110 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.namelookup_time
)
111 assert infoResp
:infoDouble
!= null
113 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.connect_time
)
114 assert infoResp
:infoDouble
!= null
116 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.appconnect_time
)
117 assert infoResp
:infoDouble
!= null
119 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.pretransfer_time
)
120 assert infoResp
:infoDouble
!= null
122 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.starttransfer_time
)
123 assert infoResp
:infoDouble
!= null
125 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.redirect_time
)
126 assert infoResp
:infoDouble
!= null
128 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.size_upload
)
129 assert infoResp
:infoDouble
!= null
131 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.size_download
)
132 assert infoResp
:infoDouble
!= null
134 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.speed_download
)
135 assert infoResp
:infoDouble
!= null
137 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.speed_upload
)
138 assert infoResp
:infoDouble
!= null
140 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.content_length_download
)
141 assert infoResp
:infoDouble
!= null
143 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.content_length_upload
)
144 assert infoResp
:infoDouble
!= null
147 var infoStr
:nullable CURLInfoResponseString
148 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.content_type
)
149 assert infoResp
:infoStr
!= null
151 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.effective_url
)
152 assert infoResp
:infoStr
!= null
154 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.redirect_url
)
155 assert infoResp
:infoStr
!= null
157 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.primary_ip
)
158 assert infoResp
:infoStr
!= null
160 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.local_ip
)
161 assert infoResp
:infoStr
!= null
163 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.ftp_entry_path
)
164 assert infoResp
:infoStr
!= null
166 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.private_data
)
167 assert infoResp
:infoStr
!= null
169 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.rtsp_session_id
)
170 assert infoResp
:infoStr
!= null
173 var infoList
:nullable CURLInfoResponseArray
174 infoList
= curl
.easy_getinfo_slist
(new CURLInfoSList.ssl_engines
)
175 assert infoResp
:infoList
!= null
177 infoList
= curl
.easy_getinfo_slist
(new CURLInfoSList.cookielist
)
178 assert infoResp
:infoList
!= null
181 var mailList
= new CURLSList.with_str
("titi")
182 mailList
.append
("toto")
183 mailList
.append
("toto2")
184 mailList
.append
("toto3")
185 mailList
.append
("toto4")
186 mailList
.append
("toto9")
187 if mailList
.is_init
then
188 var content
= mailList
.to_a
189 print
"CURLSList to array - content: {content.to_s}"
190 print
"CURLSList to array - length: {content.length.to_s}"
193 print
"CURLSList to array: CURLSList wrong init"
196 # CURLSList from Array
197 var mailRecipientsArray
= new Array[String]
198 mailRecipientsArray
.add
("tata")
199 mailRecipientsArray
.add
("tata2")
200 var mailRecipientsList
: CURLSList = mailRecipientsArray
.to_curlslist
201 if mailRecipientsList
.is_init
then
202 print
"Array to CURLSList - content: {mailRecipientsList.to_a.to_s}"
203 print
"Array to CURLSList - length: {mailRecipientsList.to_a.length.to_s}"
204 mailRecipientsList
.destroy
206 print
"CURLSList to array: CURLSList wrong init"
210 var hashMapRefined
= new HeaderMap
211 hashMapRefined
["hello"] = "toto"
212 hashMapRefined
["hello"] = "tata"
213 hashMapRefined
["allo"] = "foo"
214 print hashMapRefined
.to_url_encoded
(new CCurl.easy_init
)