File tree 1 file changed +11
-3
lines changed
1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change 61
61
let ( :curl_opts ) { nil }
62
62
63
63
def curl_and_get_json_response ( url , method : :get ) ; require 'open3'
64
+ cmd = "curl -s -v --show-error #{ curl_opts } -X #{ method . to_s . upcase } -k #{ url } "
64
65
begin
65
- stdout , status = Open3 . capture2 ( "curl -s --show-error #{ curl_opts } -X #{ method . to_s . upcase } -k #{ url } " )
66
+ out , err , status = Open3 . capture3 ( cmd )
66
67
rescue Errno ::ENOENT
67
68
fail "curl not available, make sure curl binary is installed and available on $PATH"
68
69
end
69
70
70
71
if status . success?
71
- LogStash ::Json . load ( stdout )
72
+ http_status = err . match ( /< HTTP\/ 1.1 (.*?)/ ) [ 1 ] || '0' # < HTTP/1.1 200 OK\r\n
73
+ if http_status . strip [ 0 ] . to_i > 2
74
+ warn out
75
+ fail "#{ cmd . inspect } unexpected response: #{ http_status } \n \n #{ err } "
76
+ end
77
+
78
+ LogStash ::Json . load ( out )
72
79
else
73
- fail "curl failed: #{ status } \n #{ stdout } "
80
+ warn out
81
+ fail "#{ cmd . inspect } process failed: #{ status } \n \n #{ err } "
74
82
end
75
83
end
76
84
You can’t perform that action at this time.
0 commit comments