Skip to content

Commit 2070934

Browse files
committed
Improve output file handling and expand_path
1 parent 72650d7 commit 2070934

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

plugins/requests.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def parse_args(args)
2626
'-3' => [ false, 'Use SSLv3 (SSL)' ],
2727
'-A' => [ true, 'User-Agent to send to server' ],
2828
'-d' => [ true, 'HTTP POST data' ],
29-
'-G' => [ false, 'Send the -d data with a HTTP GET' ],
29+
'-G' => [ false, 'Send the -d data with an HTTP GET' ],
3030
'-h' => [ false, 'This help text' ],
3131
'-H' => [ true, 'Custom header to pass to server' ],
3232
'-i' => [ false, 'Include headers in the output' ],
@@ -81,7 +81,7 @@ def parse_args(args)
8181
options[:print_body] = false
8282
options[:method] ||= 'HEAD'
8383
when '-o'
84-
options[:output_file] = val
84+
options[:output_file] = File.expand_path(val)
8585
when '-u'
8686
val = val.partition(':')
8787
options[:auth_username] = val[0]
@@ -174,22 +174,28 @@ def cmd_http_request(*args)
174174
ensure
175175
http_client.close
176176
end
177-
return unless response
177+
178+
unless response
179+
opts[:output_file].close unless opts[:output_file].nil?
180+
return
181+
end
178182

179183
if opts[:print_headers]
180184
output_line(opts, response.cmd_string)
181185
output_line(opts, response.headers.to_s)
182186
end
183187

184188
output_line(opts, response.body) if opts[:print_body]
185-
opts[:output_file].close unless opts[:output_file].nil?
189+
unless opts[:output_file].nil?
190+
print_status("Wrote #{opts[:output_file].tell} bytes to #{opts[:output_file].path}")
191+
opts[:output_file].close
192+
end
186193
end
187194
end
188195

189196
def initialize(framework, opts)
190197
super
191198
add_console_dispatcher(ConsoleCommandDispatcher)
192-
print_status("#{name} plugin loaded.")
193199
end
194200

195201
def cleanup

0 commit comments

Comments
 (0)