super CurlCallbacks
var curl: Curl
+ var our_body: String = ""
init do self.curl = new Curl
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}"
# 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
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}"
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