17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/epitools/browser/mechanize_progressbar.rb', line 17
def handle(ctx, params)
params[:response] = @response
body = StringIO.new
total = 0
if @response.respond_to? :content_type
pbar = ProgressBar.new(" |_ #{@response.content_type}", @response.content_length)
else
pbar = nil
end
@response.read_body { |part|
total += part.length
body.write(part)
pbar.set(total) if pbar
Mechanize.log.debug("Read #{total} bytes") if Mechanize.log
}
pbar.finish if pbar
body.rewind
res_klass = Net::HTTPResponse::CODE_TO_OBJ[@response.code.to_s]
raise ResponseCodeError.new(@response) unless res_klass
unless res_klass <= Net::HTTPRedirection
raise EOFError if (!params[:request].is_a?(Net::HTTP::Head)) && @response.content_length() && @response.content_length() != total
end
@response. { |k,v|
Mechanize.log.debug("response-header: #{ k } => #{ v }")
} if Mechanize.log
params[:response_body] = body
params[:res_klass] = res_klass
super
end
|