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 CHANGED
@@ -1,5 +1,11 @@
1
1
  = Mechanize CHANGELOG
2
2
 
3
+ == 0.7.1
4
+
5
+ * Added iPhone to the user agent aliases. [#17572]
6
+ * Fixed a bug with EOF errors in net/http. [#17570]
7
+ * Handling 0 length gzipped responses. [#17471]
8
+
3
9
  == 0.7.0
4
10
 
5
11
  * Removed Ruby 1.8.2 support
data/README.txt CHANGED
@@ -12,7 +12,7 @@ a history.
12
12
 
13
13
  == Dependencies
14
14
 
15
- * ruby 1.8.2
15
+ * ruby 1.8.4
16
16
  * hpricot[http://code.whytheluckystiff.net/hpricot/]
17
17
 
18
18
  Note that the files in the net-overrides/ directory are taken from Ruby 1.9.0.
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.0'
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
- response = http_obj.request(request, *request_data) {|response|
512
-
513
- body = StringIO.new
514
- total = 0
515
- response.read_body { |part|
516
- total += part.length
517
- body.write(part)
518
- log.debug("Read #{total} bytes") if log
519
- }
520
- body.rewind
521
-
522
- response.each_header { |k,v|
523
- log.debug("response-header: #{ k } => #{ v }")
524
- } if log
525
-
526
- content_type = nil
527
- unless response['Content-Type'].nil?
528
- data = response['Content-Type'].match(/^([^;]*)/)
529
- content_type = data[1].downcase unless data.nil?
530
- end
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
- response_body =
533
- if encoding = response['Content-Encoding']
534
- case encoding.downcase
535
- when 'gzip'
536
- log.debug('gunzip body') if log
537
- Zlib::GzipReader.new(body).read
538
- when 'x-gzip'
539
- body.read
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
- raise 'Unsupported content encoding'
550
+ body.read
542
551
  end
543
- else
544
- body.read
545
- end
546
552
 
547
- # Find our pluggable parser
548
- page = @pluggable_parser.parser(content_type).new(
549
- uri,
550
- response,
551
- response_body,
552
- response.code
553
- ) { |parser|
554
- parser.mech = self if parser.respond_to? :mech=
555
- if parser.respond_to?(:watch_for_set=) && @watch_for_set
556
- parser.watch_for_set = @watch_for_set
557
- end
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
- File.open("#{BASE_DIR}/htdocs/#{req.query['file']}", 'r') do |file|
76
- string = ""
77
- zipped = StringIO.new string, 'w'
78
- gz = Zlib::GzipWriter.new(zipped)
79
- gz.write file.read
80
- gz.close
81
- res['Content-Encoding'] = 'gzip'
82
- res['Content-Type'] = "text/html"
83
- res.body = string
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.0
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-01-14 00:00:00 -08:00
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.4.0
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