640170635b1c29de6184366946220455a2c04e08
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.
21 fun error_manager
(err
: CURLCode) do if not err
.is_ok
then print err
23 var url
= "http://example.org/"
25 var curl
= new CCurl.easy_init
26 if not curl
.is_init
then print
"failed init"
29 error
= curl
.easy_setopt
(new CURLOption.url
, url
)
32 # Activate for advanced debugging
33 #error = curl.easy_setopt(new CURLOption.verbose, 1)
36 error
= curl
.easy_perform
40 var info
:nullable CURLInfoResponseLong
41 info
= curl
.easy_getinfo_long
(new CURLInfoLong.header_size
)
42 assert infoResp
:info
!= null
44 info
= curl
.easy_getinfo_long
(new CURLInfoLong.response_code
)
45 assert infoResp
:info
!= null
47 info
= curl
.easy_getinfo_long
(new CURLInfoLong.http_connectcode
)
48 assert infoResp
:info
!= null
50 info
= curl
.easy_getinfo_long
(new CURLInfoLong.filetime
)
51 assert infoResp
:info
!= null
53 info
= curl
.easy_getinfo_long
(new CURLInfoLong.redirect_count
)
54 assert infoResp
:info
!= null
56 info
= curl
.easy_getinfo_long
(new CURLInfoLong.request_size
)
57 assert infoResp
:info
!= null
59 info
= curl
.easy_getinfo_long
(new CURLInfoLong.ssl_verifyresult
)
60 assert infoResp
:info
!= null
62 info
= curl
.easy_getinfo_long
(new CURLInfoLong.httpauth_avail
)
63 assert infoResp
:info
!= null
65 info
= curl
.easy_getinfo_long
(new CURLInfoLong.proxyauth_avail
)
66 assert infoResp
:info
!= null
68 info
= curl
.easy_getinfo_long
(new CURLInfoLong.os_errno
)
69 assert infoResp
:info
!= null
71 info
= curl
.easy_getinfo_long
(new CURLInfoLong.primary_port
)
72 assert infoResp
:info
!= null
74 info
= curl
.easy_getinfo_long
(new CURLInfoLong.num_connects
)
75 assert infoResp
:info
!= null
77 info
= curl
.easy_getinfo_long
(new CURLInfoLong.local_port
)
78 assert infoResp
:info
!= null
80 info
= curl
.easy_getinfo_long
(new CURLInfoLong.lastsocket
)
81 assert infoResp
:info
!= null
83 info
= curl
.easy_getinfo_long
(new CURLInfoLong.condition_unmet
)
84 assert infoResp
:info
!= null
86 info
= curl
.easy_getinfo_long
(new CURLInfoLong.rtsp_client_cseq
)
87 assert infoResp
:info
!= null
89 info
= curl
.easy_getinfo_long
(new CURLInfoLong.rtsp_server_cseq
)
90 assert infoResp
:info
!= null
92 info
= curl
.easy_getinfo_long
(new CURLInfoLong.rtsp_cseq_recv
)
93 assert infoResp
:info
!= null
96 var infoDouble
: nullable CURLInfoResponseDouble
97 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.total_time
)
98 assert infoResp
:infoDouble
!= null
100 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.namelookup_time
)
101 assert infoResp
:infoDouble
!= null
103 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.connect_time
)
104 assert infoResp
:infoDouble
!= null
106 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.appconnect_time
)
107 assert infoResp
:infoDouble
!= null
109 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.pretransfer_time
)
110 assert infoResp
:infoDouble
!= null
112 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.starttransfer_time
)
113 assert infoResp
:infoDouble
!= null
115 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.redirect_time
)
116 assert infoResp
:infoDouble
!= null
118 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.size_upload
)
119 assert infoResp
:infoDouble
!= null
121 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.size_download
)
122 assert infoResp
:infoDouble
!= null
124 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.speed_download
)
125 assert infoResp
:infoDouble
!= null
127 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.speed_upload
)
128 assert infoResp
:infoDouble
!= null
130 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.content_length_download
)
131 assert infoResp
:infoDouble
!= null
133 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.content_length_upload
)
134 assert infoResp
:infoDouble
!= null
137 var infoStr
:nullable CURLInfoResponseString
138 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.content_type
)
139 assert infoResp
:infoStr
!= null
141 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.effective_url
)
142 assert infoResp
:infoStr
!= null
144 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.redirect_url
)
145 assert infoResp
:infoStr
!= null
147 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.primary_ip
)
148 assert infoResp
:infoStr
!= null
150 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.local_ip
)
151 assert infoResp
:infoStr
!= null
153 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.ftp_entry_path
)
154 assert infoResp
:infoStr
!= null
156 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.private_data
)
157 assert infoResp
:infoStr
!= null
159 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.rtsp_session_id
)
160 assert infoResp
:infoStr
!= null
163 var infoList
:nullable CURLInfoResponseArray
164 infoList
= curl
.easy_getinfo_slist
(new CURLInfoSList.ssl_engines
)
165 assert infoResp
:infoList
!= null
167 infoList
= curl
.easy_getinfo_slist
(new CURLInfoSList.cookielist
)
168 assert infoResp
:infoList
!= null
171 var mailList
= new CURLSList.with_str
("titi")
172 mailList
.append
("toto")
173 mailList
.append
("toto2")
174 mailList
.append
("toto3")
175 mailList
.append
("toto4")
176 mailList
.append
("toto9")
177 if mailList
.is_init
then
178 var content
= mailList
.to_a
179 print
"CURLSList to array - content: {content.to_s}"
180 print
"CURLSList to array - length: {content.length.to_s}"
183 print
"CURLSList to array: CURLSList wrong init"
186 # CURLSList from Array
187 var mailRecipientsArray
= new Array[String]
188 mailRecipientsArray
.add
("tata")
189 mailRecipientsArray
.add
("tata2")
190 var mailRecipientsList
: CURLSList = mailRecipientsArray
.to_curlslist
191 if mailRecipientsList
.is_init
then
192 print
"Array to CURLSList - content: {mailRecipientsList.to_a.to_s}"
193 print
"Array to CURLSList - length: {mailRecipientsList.to_a.length.to_s}"
194 mailRecipientsList
.destroy
196 print
"CURLSList to array: CURLSList wrong init"
200 var hashMapRefined
= new HeaderMap
201 hashMapRefined
["hello"] = "toto"
202 hashMapRefined
["hello"] = "tata"
203 hashMapRefined
["allo"] = "foo"
204 print hashMapRefined
.to_url_encoded
(new CCurl.easy_init
)