tests: replace usage of `is` with `is_same_instance`
[nit.git] / examples / curl_http.nit
index 50c46e5..db7e113 100644 (file)
@@ -24,6 +24,7 @@ class MyHttpFetcher
   super CurlCallbacks
 
   var curl: Curl
+  var our_body: String = ""
 
   init do self.curl = new Curl
 
@@ -33,10 +34,13 @@ class MyHttpFetcher
   fun request(url: String): nullable CurlRequest do return self.curl.http_request(url)
 
   # Header callback
-  redef fun header_callback(line: String) do print "Header_callback : {line}"
+  redef fun header_callback(line: String) do
+       # We keep this callback silent for testing purposes
+    #if not line.has_prefix("Date:") then print "Header_callback : {line}"
+  end
 
   # Body callback
-  redef fun body_callback(line: String) do print "Body_callback : {line}"
+  redef fun body_callback(line: String) do self.our_body = "{self.our_body}{line}"
 
   # Stream callback - Cf : No one is registered
   redef fun stream_callback(buffer: String, size: Int, count: Int) do print "Stream_callback : {buffer} - {size} - {count}"
@@ -45,7 +49,7 @@ end
 
 # Program
 if args.length < 2 then
-  print "Usage {sys.program_name} <method wished [POST, GET, GET_FILE]> <target url>"
+  print "Usage: curl_http <method wished [POST, GET, GET_FILE]> <target url>"
 else
 
   var myHttpFetcher = new MyHttpFetcher
@@ -85,6 +89,8 @@ else
       postContentRequest.verbose = false
       var postResponse = postContentRequest.execute
 
+      print "Our body from the callback : {myHttpFetcher.our_body}"
+
       if postResponse isa CurlResponseSuccess then
         print "*** Answer ***"
         print "Status code : {postResponse.status_code}"
@@ -106,7 +112,7 @@ else
       var headers = new HeaderMap
       headers["Accept"] = "Moo"
       downloadFileRequest.headers = headers
-      downloadFileRequest.verbose = true
+      downloadFileRequest.verbose = false
       var downloadResponse = downloadFileRequest.download_to_file(null)
 
       if downloadResponse isa CurlFileResponseSuccess then