mechanize 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of mechanize might be problematic. Click here for more details.
- data/CHANGELOG.txt +6 -0
- data/README.txt +1 -1
- data/lib/www/mechanize.rb +58 -46
- data/test/servlets.rb +13 -9
- data/test/tc_gzipping.rb +6 -0
- metadata +3 -3
data/CHANGELOG.txt
CHANGED
data/README.txt
CHANGED
data/lib/www/mechanize.rb
CHANGED
@@ -38,7 +38,7 @@ module WWW
|
|
38
38
|
class Mechanize
|
39
39
|
##
|
40
40
|
# The version of Mechanize you are using.
|
41
|
-
VERSION = '0.7.
|
41
|
+
VERSION = '0.7.1'
|
42
42
|
|
43
43
|
##
|
44
44
|
# User Agent aliases
|
@@ -51,6 +51,7 @@ module WWW
|
|
51
51
|
'Mac Mozilla' => 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.4a) Gecko/20030401',
|
52
52
|
'Linux Mozilla' => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624',
|
53
53
|
'Linux Konqueror' => 'Mozilla/5.0 (compatible; Konqueror/3; Linux)',
|
54
|
+
'iPhone' => 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1C28 Safari/419.3',
|
54
55
|
'Mechanize' => "WWW-Mechanize/#{VERSION} (http://rubyforge.org/projects/mechanize/)"
|
55
56
|
}
|
56
57
|
|
@@ -508,56 +509,67 @@ module WWW
|
|
508
509
|
cache_obj[:last_request_time] = Time.now.to_i
|
509
510
|
|
510
511
|
# Send the request
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
512
|
+
begin
|
513
|
+
response = http_obj.request(request, *request_data) {|response|
|
514
|
+
|
515
|
+
body = StringIO.new
|
516
|
+
total = 0
|
517
|
+
response.read_body { |part|
|
518
|
+
total += part.length
|
519
|
+
body.write(part)
|
520
|
+
log.debug("Read #{total} bytes") if log
|
521
|
+
}
|
522
|
+
body.rewind
|
523
|
+
|
524
|
+
response.each_header { |k,v|
|
525
|
+
log.debug("response-header: #{ k } => #{ v }")
|
526
|
+
} if log
|
527
|
+
|
528
|
+
content_type = nil
|
529
|
+
unless response['Content-Type'].nil?
|
530
|
+
data = response['Content-Type'].match(/^([^;]*)/)
|
531
|
+
content_type = data[1].downcase unless data.nil?
|
532
|
+
end
|
531
533
|
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
534
|
+
response_body =
|
535
|
+
if encoding = response['Content-Encoding']
|
536
|
+
case encoding.downcase
|
537
|
+
when 'gzip'
|
538
|
+
log.debug('gunzip body') if log
|
539
|
+
if response['Content-Length'].to_i > 0
|
540
|
+
Zlib::GzipReader.new(body).read
|
541
|
+
else
|
542
|
+
''
|
543
|
+
end
|
544
|
+
when 'x-gzip'
|
545
|
+
body.read
|
546
|
+
else
|
547
|
+
raise 'Unsupported content encoding'
|
548
|
+
end
|
540
549
|
else
|
541
|
-
|
550
|
+
body.read
|
542
551
|
end
|
543
|
-
else
|
544
|
-
body.read
|
545
|
-
end
|
546
552
|
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
553
|
+
# Find our pluggable parser
|
554
|
+
page = @pluggable_parser.parser(content_type).new(
|
555
|
+
uri,
|
556
|
+
response,
|
557
|
+
response_body,
|
558
|
+
response.code
|
559
|
+
) { |parser|
|
560
|
+
parser.mech = self if parser.respond_to? :mech=
|
561
|
+
if parser.respond_to?(:watch_for_set=) && @watch_for_set
|
562
|
+
parser.watch_for_set = @watch_for_set
|
563
|
+
end
|
564
|
+
}
|
559
565
|
|
560
|
-
|
566
|
+
}
|
567
|
+
rescue EOFError
|
568
|
+
log.error("Rescuing EOF error") if log
|
569
|
+
http_obj.finish
|
570
|
+
http_obj.start
|
571
|
+
retry
|
572
|
+
end
|
561
573
|
|
562
574
|
# If the server sends back keep alive options, save them
|
563
575
|
if keep_alive_info = response['keep-alive']
|
data/test/servlets.rb
CHANGED
@@ -72,16 +72,20 @@ end
|
|
72
72
|
class GzipServlet < WEBrick::HTTPServlet::AbstractServlet
|
73
73
|
def do_GET(req, res)
|
74
74
|
if req['Accept-Encoding'] =~ /gzip/
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
75
|
+
if req.query['file']
|
76
|
+
File.open("#{BASE_DIR}/htdocs/#{req.query['file']}", 'r') do |file|
|
77
|
+
string = ""
|
78
|
+
zipped = StringIO.new string, 'w'
|
79
|
+
gz = Zlib::GzipWriter.new(zipped)
|
80
|
+
gz.write file.read
|
81
|
+
gz.close
|
82
|
+
res.body = string
|
83
|
+
end
|
84
|
+
else
|
85
|
+
res.body = ''
|
84
86
|
end
|
87
|
+
res['Content-Encoding'] = 'gzip'
|
88
|
+
res['Content-Type'] = "text/html"
|
85
89
|
else
|
86
90
|
raise 'no gzip'
|
87
91
|
end
|
data/test/tc_gzipping.rb
CHANGED
@@ -5,6 +5,12 @@ class TestGzip < Test::Unit::TestCase
|
|
5
5
|
@agent = WWW::Mechanize.new
|
6
6
|
end
|
7
7
|
|
8
|
+
def test_request_empty_gzip
|
9
|
+
assert_nothing_raised do
|
10
|
+
page = @agent.get("http://localhost/gzip")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
8
14
|
def test_request_gzip
|
9
15
|
page = nil
|
10
16
|
assert_nothing_raised do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mechanize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Patterson
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-03-04 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -28,7 +28,7 @@ dependencies:
|
|
28
28
|
requirements:
|
29
29
|
- - ">="
|
30
30
|
- !ruby/object:Gem::Version
|
31
|
-
version: 1.
|
31
|
+
version: 1.5.1
|
32
32
|
version:
|
33
33
|
description: The Mechanize library is used for automating interaction with websites. Mechanize automatically stores and sends cookies, follows redirects, can follow links, and submit forms. Form fields can be populated and submitted. Mechanize also keeps track of the sites that you have visited as a history.
|
34
34
|
email: aaronp@rubyforge.org
|