mechanize 2.4 → 2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mechanize might be problematic. Click here for more details.

Files changed (57) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG.rdoc +30 -4
  3. data/EXAMPLES.rdoc +2 -2
  4. data/GUIDE.rdoc +13 -13
  5. data/Manifest.txt +30 -0
  6. data/README.rdoc +19 -2
  7. data/lib/mechanize.rb +30 -7
  8. data/lib/mechanize/chunked_termination_error.rb +7 -0
  9. data/lib/mechanize/form.rb +7 -5
  10. data/lib/mechanize/form/radio_button.rb +14 -0
  11. data/lib/mechanize/http/agent.rb +54 -24
  12. data/lib/mechanize/http/auth_store.rb +6 -0
  13. data/lib/mechanize/http/content_disposition_parser.rb +1 -1
  14. data/lib/mechanize/monkey_patch.rb +3 -2
  15. data/lib/mechanize/page.rb +0 -2
  16. data/lib/mechanize/parser.rb +2 -2
  17. data/lib/mechanize/test_case.rb +70 -435
  18. data/lib/mechanize/test_case/.document +1 -0
  19. data/lib/mechanize/test_case/bad_chunking_servlet.rb +14 -0
  20. data/lib/mechanize/test_case/basic_auth_servlet.rb +24 -0
  21. data/lib/mechanize/test_case/content_type_servlet.rb +8 -0
  22. data/lib/mechanize/test_case/digest_auth_servlet.rb +33 -0
  23. data/lib/mechanize/test_case/file_upload_servlet.rb +20 -0
  24. data/lib/mechanize/test_case/form_servlet.rb +55 -0
  25. data/lib/mechanize/test_case/gzip_servlet.rb +32 -0
  26. data/lib/mechanize/test_case/header_servlet.rb +14 -0
  27. data/lib/mechanize/test_case/http_refresh_servlet.rb +9 -0
  28. data/lib/mechanize/test_case/infinite_redirect_servlet.rb +10 -0
  29. data/lib/mechanize/test_case/infinite_refresh_servlet.rb +10 -0
  30. data/lib/mechanize/test_case/many_cookies_as_string_servlet.rb +37 -0
  31. data/lib/mechanize/test_case/many_cookies_servlet.rb +33 -0
  32. data/lib/mechanize/test_case/modified_since_servlet.rb +21 -0
  33. data/lib/mechanize/test_case/ntlm_servlet.rb +30 -0
  34. data/lib/mechanize/test_case/one_cookie_no_spaces_servlet.rb +11 -0
  35. data/lib/mechanize/test_case/one_cookie_servlet.rb +11 -0
  36. data/lib/mechanize/test_case/quoted_value_cookie_servlet.rb +11 -0
  37. data/lib/mechanize/test_case/redirect_servlet.rb +13 -0
  38. data/lib/mechanize/test_case/referer_servlet.rb +12 -0
  39. data/lib/mechanize/test_case/refresh_with_empty_url.rb +15 -0
  40. data/lib/mechanize/test_case/refresh_without_url.rb +14 -0
  41. data/lib/mechanize/test_case/response_code_servlet.rb +15 -0
  42. data/lib/mechanize/test_case/send_cookies_servlet.rb +19 -0
  43. data/lib/mechanize/test_case/server.rb +36 -0
  44. data/lib/mechanize/test_case/servlets.rb +55 -0
  45. data/lib/mechanize/test_case/verb_servlet.rb +11 -0
  46. data/test/test_mechanize.rb +12 -12
  47. data/test/test_mechanize_file.rb +11 -0
  48. data/test/test_mechanize_file_response.rb +23 -0
  49. data/test/test_mechanize_form.rb +34 -0
  50. data/test/test_mechanize_form_radio_button.rb +19 -2
  51. data/test/test_mechanize_http_agent.rb +104 -26
  52. data/test/test_mechanize_http_auth_store.rb +23 -0
  53. data/test/test_mechanize_http_content_disposition_parser.rb +6 -0
  54. data/test/test_mechanize_page.rb +3 -5
  55. data/test/test_mechanize_page_link.rb +0 -32
  56. metadata +39 -8
  57. metadata.gz.sig +2 -2
@@ -0,0 +1,15 @@
1
+ class RefreshWithEmptyUrl < WEBrick::HTTPServlet::AbstractServlet
2
+ @@count = 0
3
+ def do_GET(req, res)
4
+ address = "#{req.host}:#{req.port}"
5
+
6
+ res.content_type = "text/html"
7
+ @@count += 1
8
+ if @@count > 1
9
+ res['Refresh'] = "0; url=http://#{address}/";
10
+ else
11
+ res['Refresh'] = "0; url=";
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,14 @@
1
+ class RefreshWithoutUrl < WEBrick::HTTPServlet::AbstractServlet
2
+ @@count = 0
3
+ def do_GET(req, res)
4
+ address = "#{req.host}:#{req.port}"
5
+ res['Content-Type'] = "text/html"
6
+ @@count += 1
7
+ if @@count > 1
8
+ res['Refresh'] = "0; url=http://#{address}/";
9
+ else
10
+ res['Refresh'] = "0";
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,15 @@
1
+ class ResponseCodeServlet < WEBrick::HTTPServlet::AbstractServlet
2
+ def do_GET(req, res)
3
+ res['Content-Type'] = req.query['ct'] || "text/html"
4
+ if req.query['code']
5
+ code = req.query['code'].to_i
6
+ case code
7
+ when 300, 301, 302, 303, 304, 305, 307
8
+ res['Location'] = "/index.html"
9
+ end
10
+ res.status = code
11
+ else
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,19 @@
1
+ class SendCookiesServlet < WEBrick::HTTPServlet::AbstractServlet
2
+ def do_GET(req, res)
3
+ res.content_type = 'text/html'
4
+
5
+ cookies = req.cookies.map do |c|
6
+ "<li><a href=\"#\">#{c.name}:#{c.value}</a>"
7
+ end.join "\n"
8
+
9
+ res.body = <<-BODY
10
+ <!DOCTYPE html>
11
+ <title>Your cookies</title>
12
+
13
+ <ul>
14
+ #{cookies}
15
+ </ul>
16
+ BODY
17
+ end
18
+ end
19
+
@@ -0,0 +1,36 @@
1
+ require 'webrick'
2
+ require 'mechanize/test_case/servlets'
3
+
4
+ server = WEBrick::HTTPServer.new :Port => 8000
5
+ server.mount_proc '/' do |req, res|
6
+ res.content_type = 'text/html'
7
+
8
+ servlets = MECHANIZE_TEST_CASE_SERVLETS.map do |path, servlet|
9
+ "<dt>#{servlet}<dd><a href=\"#{path}\">#{path}</a>"
10
+ end.join "\n"
11
+
12
+ res.body = <<-BODY
13
+ <!DOCTYPE html>
14
+ <title>Mechanize Test Case Servlets</title>
15
+ <p>This server allows you to test various mechanize behavior against other
16
+ HTTP clients. Some endpoints may require headers be set to have a reasonable
17
+ function, or may respond diffently to POST vs GET requests. Please see the
18
+ servlet implementation and mechanize tests for further details.
19
+
20
+ <p>Here are the servlet endpoints available:
21
+
22
+ <dl>
23
+ #{servlets}
24
+ </dl>
25
+ BODY
26
+ end
27
+
28
+ MECHANIZE_TEST_CASE_SERVLETS.each do |path, servlet|
29
+ server.mount path, servlet
30
+ end
31
+
32
+ trap 'INT' do server.shutdown end
33
+ trap 'TERM' do server.shutdown end
34
+
35
+ server.start
36
+
@@ -0,0 +1,55 @@
1
+ require 'mechanize/test_case/bad_chunking_servlet'
2
+ require 'mechanize/test_case/basic_auth_servlet'
3
+ require 'mechanize/test_case/content_type_servlet'
4
+ require 'mechanize/test_case/digest_auth_servlet'
5
+ require 'mechanize/test_case/file_upload_servlet'
6
+ require 'mechanize/test_case/form_servlet'
7
+ require 'mechanize/test_case/gzip_servlet'
8
+ require 'mechanize/test_case/header_servlet'
9
+ require 'mechanize/test_case/http_refresh_servlet'
10
+ require 'mechanize/test_case/infinite_redirect_servlet'
11
+ require 'mechanize/test_case/infinite_refresh_servlet'
12
+ require 'mechanize/test_case/many_cookies_as_string_servlet'
13
+ require 'mechanize/test_case/many_cookies_servlet'
14
+ require 'mechanize/test_case/modified_since_servlet'
15
+ require 'mechanize/test_case/ntlm_servlet'
16
+ require 'mechanize/test_case/one_cookie_no_spaces_servlet'
17
+ require 'mechanize/test_case/one_cookie_servlet'
18
+ require 'mechanize/test_case/quoted_value_cookie_servlet'
19
+ require 'mechanize/test_case/redirect_servlet'
20
+ require 'mechanize/test_case/referer_servlet'
21
+ require 'mechanize/test_case/refresh_with_empty_url'
22
+ require 'mechanize/test_case/refresh_without_url'
23
+ require 'mechanize/test_case/response_code_servlet'
24
+ require 'mechanize/test_case/send_cookies_servlet'
25
+ require 'mechanize/test_case/verb_servlet'
26
+
27
+ MECHANIZE_TEST_CASE_SERVLETS = {
28
+ '/bad_chunking' => BadChunkingServlet,
29
+ '/basic_auth' => BasicAuthServlet,
30
+ '/content_type_test' => ContentTypeServlet,
31
+ '/digest_auth' => DigestAuthServlet,
32
+ '/file_upload' => FileUploadServlet,
33
+ '/form post' => FormServlet,
34
+ '/form_post' => FormServlet,
35
+ '/gzip' => GzipServlet,
36
+ '/http_headers' => HeaderServlet,
37
+ '/http_refresh' => HttpRefreshServlet,
38
+ '/if_modified_since' => ModifiedSinceServlet,
39
+ '/infinite_redirect' => InfiniteRedirectServlet,
40
+ '/infinite_refresh' => InfiniteRefreshServlet,
41
+ '/many_cookies' => ManyCookiesServlet,
42
+ '/many_cookies_as_string' => ManyCookiesAsStringServlet,
43
+ '/ntlm' => NTLMServlet,
44
+ '/one_cookie' => OneCookieServlet,
45
+ '/one_cookie_no_space' => OneCookieNoSpacesServlet,
46
+ '/quoted_value_cookie' => QuotedValueCookieServlet,
47
+ '/redirect' => RedirectServlet,
48
+ '/referer' => RefererServlet,
49
+ '/refresh_with_empty_url' => RefreshWithEmptyUrl,
50
+ '/refresh_without_url' => RefreshWithoutUrl,
51
+ '/response_code' => ResponseCodeServlet,
52
+ '/send_cookies' => SendCookiesServlet,
53
+ '/verb' => VerbServlet,
54
+ }
55
+
@@ -0,0 +1,11 @@
1
+ class VerbServlet < WEBrick::HTTPServlet::AbstractServlet
2
+ %w[HEAD GET POST PUT DELETE].each do |verb|
3
+ eval <<-METHOD
4
+ def do_#{verb}(req, res)
5
+ res.header['X-Request-Method'] = #{verb.dump}
6
+ res.body = #{verb.dump}
7
+ end
8
+ METHOD
9
+ end
10
+ end
11
+
@@ -434,15 +434,15 @@ but not <a href="/" rel="me nofollow">this</a>!
434
434
  @mech.follow_meta_refresh = true
435
435
  @mech.follow_meta_refresh_self = true
436
436
 
437
- page = @mech.get('http://localhost/refresh_with_empty_url')
437
+ page = @mech.get('http://example/refresh_with_empty_url')
438
438
 
439
439
  assert_equal(3, @mech.history.length)
440
- assert_equal('http://localhost/refresh_with_empty_url',
440
+ assert_equal('http://example/refresh_with_empty_url',
441
441
  @mech.history[0].uri.to_s)
442
- assert_equal('http://localhost/refresh_with_empty_url',
442
+ assert_equal('http://example/refresh_with_empty_url',
443
443
  @mech.history[1].uri.to_s)
444
- assert_equal('http://localhost/index.html', page.uri.to_s)
445
- assert_equal('http://localhost/index.html', @mech.history.last.uri.to_s)
444
+ assert_equal('http://example/', page.uri.to_s)
445
+ assert_equal('http://example/', @mech.history.last.uri.to_s)
446
446
  end
447
447
 
448
448
  def test_get_follow_meta_refresh_in_body
@@ -460,15 +460,15 @@ but not <a href="/" rel="me nofollow">this</a>!
460
460
  @mech.follow_meta_refresh = true
461
461
  @mech.follow_meta_refresh_self = true
462
462
 
463
- page = @mech.get('http://localhost/refresh_without_url')
463
+ page = @mech.get('http://example/refresh_without_url')
464
464
 
465
465
  assert_equal(3, @mech.history.length)
466
- assert_equal('http://localhost/refresh_without_url',
466
+ assert_equal('http://example/refresh_without_url',
467
467
  @mech.history[0].uri.to_s)
468
- assert_equal('http://localhost/refresh_without_url',
468
+ assert_equal('http://example/refresh_without_url',
469
469
  @mech.history[1].uri.to_s)
470
- assert_equal('http://localhost/index.html', page.uri.to_s)
471
- assert_equal('http://localhost/index.html', @mech.history.last.uri.to_s)
470
+ assert_equal('http://example/', page.uri.to_s)
471
+ assert_equal('http://example/', @mech.history.last.uri.to_s)
472
472
  end
473
473
 
474
474
  def test_get_follow_meta_refresh_referer_not_sent
@@ -566,9 +566,9 @@ but not <a href="/" rel="me nofollow">this</a>!
566
566
  requests << request
567
567
  }
568
568
 
569
- page = @mech.get('http://localhost/http_refresh?refresh_time=0')
569
+ page = @mech.get('http://example/http_refresh?refresh_time=0')
570
570
 
571
- assert_equal('http://localhost/index.html', page.uri.to_s)
571
+ assert_equal('http://example/', page.uri.to_s)
572
572
  assert_equal(2, @mech.history.length)
573
573
  assert_nil requests.last['referer']
574
574
  end
@@ -16,7 +16,18 @@ class TestMechanizeFile < Mechanize::TestCase
16
16
  Dir.chdir dir do
17
17
  page.save 'test.html'
18
18
 
19
+ assert File.exist? 'test.html'
19
20
  assert_equal '0123456789', File.read('test.html')
21
+
22
+ page.save 'test.html'
23
+
24
+ assert File.exist? 'test.html.1'
25
+ assert_equal '0123456789', File.read('test.html.1')
26
+
27
+ page.save 'test.html'
28
+
29
+ assert File.exist? 'test.html.2'
30
+ assert_equal '0123456789', File.read('test.html.2')
20
31
  end
21
32
  end
22
33
  end
@@ -0,0 +1,23 @@
1
+ require 'mechanize/test_case'
2
+
3
+ class TestMechanizeFileResponse < Mechanize::TestCase
4
+
5
+ def test_content_type
6
+ Tempfile.open %w[pi .nothtml] do |tempfile|
7
+ res = Mechanize::FileResponse.new tempfile.path
8
+ assert_equal nil, res['content-type']
9
+ end
10
+
11
+ Tempfile.open %w[pi .xhtml] do |tempfile|
12
+ res = Mechanize::FileResponse.new tempfile.path
13
+ assert_equal 'text/html', res['content-type']
14
+ end
15
+
16
+ Tempfile.open %w[pi .html] do |tempfile|
17
+ res = Mechanize::FileResponse.new tempfile.path
18
+ assert_equal 'text/html', res['Content-Type']
19
+ end
20
+ end
21
+
22
+ end
23
+
@@ -65,6 +65,40 @@ class TestMechanizeForm < Mechanize::TestCase
65
65
  assert query.all? { |x| x[1] == '' }
66
66
  end
67
67
 
68
+ def test_build_query_radio_button_duplicate
69
+ html = Nokogiri::HTML <<-HTML
70
+ <form>
71
+ <input type=radio name=name value=a checked=true>
72
+ <input type=radio name=name value=a checked=true>
73
+ </form>
74
+ HTML
75
+
76
+ form = Mechanize::Form.new html.at('form'), @mech, @page
77
+
78
+ query = form.build_query
79
+
80
+ assert_equal [%w[name a]], query
81
+ end
82
+
83
+ def test_build_query_radio_button_multiple_checked
84
+ html = Nokogiri::HTML <<-HTML
85
+ <form>
86
+ <input type=radio name=name value=a checked=true>
87
+ <input type=radio name=name value=b checked=true>
88
+ </form>
89
+ HTML
90
+
91
+ form = Mechanize::Form.new html.at('form'), @mech, @page
92
+
93
+ e = assert_raises Mechanize::Error do
94
+ form.build_query
95
+ end
96
+
97
+ assert_equal 'radiobuttons "a, b" are checked in the "name" group, ' \
98
+ 'only one is allowed',
99
+ e.message
100
+ end
101
+
68
102
  def test_method_missing_get
69
103
  page = html_page <<-BODY
70
104
  <form>
@@ -12,7 +12,8 @@ class TestMechanizeFormRadioButton < Mechanize::TestCase
12
12
  <input type="radio" name="color" value="brown">
13
13
  <input type="radio" name="color" value="green">
14
14
  <input type="radio" name="color" value="red">
15
- <input type="radio" name="color" value="yellow">
15
+ <input type="radio" name="color" value="yellow" id="a">
16
+ <input type="radio" name="color" value="yellow" id="b">
16
17
 
17
18
  <input type="submit" value="Submit">
18
19
  </form>
@@ -24,7 +25,7 @@ class TestMechanizeFormRadioButton < Mechanize::TestCase
24
25
  @brown = @form.radiobutton_with :value => 'brown'
25
26
  @green = @form.radiobutton_with :value => 'green'
26
27
  @red = @form.radiobutton_with :value => 'red'
27
- @yellow = @form.radiobutton_with :value => 'yellow'
28
+ @yellow = @form.radiobutton_with :id => 'a'
28
29
  end
29
30
 
30
31
  def test_check
@@ -58,6 +59,22 @@ class TestMechanizeFormRadioButton < Mechanize::TestCase
58
59
  refute @blue.checked?
59
60
  end
60
61
 
62
+ def test_equals2
63
+ refute_equal @yellow, @red
64
+
65
+ other_yellow = @form.radiobutton_with :id => 'b'
66
+
67
+ assert_equal @yellow, other_yellow
68
+ end
69
+
70
+ def test_hash
71
+ refute_equal @yellow.hash, @red.hash
72
+
73
+ other_yellow = @form.radiobutton_with :id => 'b'
74
+
75
+ assert_equal @yellow.hash, other_yellow.hash
76
+ end
77
+
61
78
  def test_label
62
79
  assert_equal 'Blue', @blue.label.text
63
80
  end
@@ -218,6 +218,14 @@ class TestMechanizeHttpAgent < Mechanize::TestCase
218
218
  @agent.fetch URI 'http://example/index.html'
219
219
  end
220
220
 
221
+ def test_fetch_ignore_bad_chunking
222
+ @agent.ignore_bad_chunking = true
223
+
224
+ file = @agent.fetch 'http://example/bad_chunking'
225
+
226
+ assert_equal '0123456789', file.content
227
+ end
228
+
221
229
  def test_fetch_post_connect_hook
222
230
  response = nil
223
231
  @agent.post_connect_hooks << lambda { |_, _, res, _| response = res }
@@ -227,6 +235,14 @@ class TestMechanizeHttpAgent < Mechanize::TestCase
227
235
  assert response
228
236
  end
229
237
 
238
+ def test_fetch_redirect_header
239
+ page = @agent.fetch('http://example/redirect', :get,
240
+ 'X-Location' => '/http_headers',
241
+ 'Range' => 'bytes=0-99999')
242
+
243
+ assert_match 'range|bytes=0-999', page.body
244
+ end
245
+
230
246
  def test_fetch_server_error
231
247
  e = assert_raises Mechanize::ResponseCodeError do
232
248
  @mech.get 'http://localhost/response_code?code=500'
@@ -874,13 +890,49 @@ class TestMechanizeHttpAgent < Mechanize::TestCase
874
890
  assert_match %r%error handling content-encoding gzip:%, e.message
875
891
  assert_match %r%Zlib%, e.message
876
892
 
877
- assert_match %r%unable to gunzip response, trying raw inflate%, log.string
878
- assert_match %r%unable to gunzip response:%, log.string
893
+ assert_match %r%unable to gunzip response: unexpected end of file%,
894
+ log.string
895
+ assert_match %r%unable to inflate response: buffer error%,
896
+ log.string
897
+
898
+ assert body_io.closed?
899
+ end
900
+
901
+ def test_response_content_encoding_gzip_checksum_corrupt_crc
902
+ log = StringIO.new
903
+ logger = Logger.new log
904
+ @agent.context.log = logger
905
+
906
+ @res.instance_variable_set :@header, 'content-encoding' => %w[gzip]
907
+ body_io = StringIO.new \
908
+ "\037\213\b\0002\002\225M\000\003+H,*\001\000\306p\017J\004\000\000\000"
909
+
910
+ body = @agent.response_content_encoding @res, body_io
911
+
912
+ assert_equal 'part', body.read
913
+
914
+ assert body_io.closed?
915
+
916
+ assert_match %r%invalid compressed data -- crc error%, log.string
917
+ end
918
+
919
+ def test_response_content_encoding_gzip_checksum_corrupt_length
920
+ log = StringIO.new
921
+ logger = Logger.new log
922
+ @agent.context.log = logger
923
+
924
+ @res.instance_variable_set :@header, 'content-encoding' => %w[gzip]
925
+ body_io = StringIO.new \
926
+ "\037\213\b\0002\002\225M\000\003+H,*\001\000\306p\017I\005\000\000\000"
927
+
928
+ body = @agent.response_content_encoding @res, body_io
879
929
 
880
930
  assert body_io.closed?
931
+
932
+ assert_match %r%invalid compressed data -- length error%, log.string
881
933
  end
882
934
 
883
- def test_response_content_encoding_gzip_corrupt_checksum
935
+ def test_response_content_encoding_gzip_checksum_truncated
884
936
  log = StringIO.new
885
937
  logger = Logger.new log
886
938
  @agent.context.log = logger
@@ -889,14 +941,11 @@ class TestMechanizeHttpAgent < Mechanize::TestCase
889
941
  body_io = StringIO.new \
890
942
  "\037\213\b\0002\002\225M\000\003+H,*\001\000\306p\017I\004\000\000"
891
943
 
892
- e = assert_raises Mechanize::Error do
893
- @agent.response_content_encoding @res, body_io
894
- end
944
+ body = @agent.response_content_encoding @res, body_io
895
945
 
896
- assert_match %r%error handling content-encoding gzip:%, e.message
897
- assert_match %r%Zlib%, e.message
946
+ assert body_io.closed?
898
947
 
899
- assert_match %r%unable to gunzip response, trying raw inflate%, log.string
948
+ assert_match %r%unable to gunzip response: footer is not found%, log.string
900
949
  end
901
950
 
902
951
  def test_response_content_encoding_gzip_empty
@@ -926,6 +975,18 @@ class TestMechanizeHttpAgent < Mechanize::TestCase
926
975
  assert_equal Encoding::BINARY, content.encoding if have_encoding?
927
976
  end
928
977
 
978
+ def test_response_content_encoding_gzip_no_footer
979
+ @res.instance_variable_set :@header, 'content-encoding' => %w[gzip]
980
+ body_io = StringIO.new \
981
+ "\037\213\b\0002\002\225M\000\003+H,*\001\000"
982
+
983
+ body = @agent.response_content_encoding @res, body_io
984
+
985
+ assert_equal 'part', body.read
986
+
987
+ assert body_io.closed?
988
+ end
989
+
929
990
  def test_response_content_encoding_none
930
991
  @res.instance_variable_set :@header, 'content-encoding' => %w[none]
931
992
 
@@ -1168,6 +1229,21 @@ class TestMechanizeHttpAgent < Mechanize::TestCase
1168
1229
  assert_equal Encoding::BINARY, body.encoding if body.respond_to? :encoding
1169
1230
  end
1170
1231
 
1232
+ def test_response_read_chunked_no_trailer
1233
+ @res['Transfer-Encoding'] = 'chunked'
1234
+ def @res.content_length() end
1235
+ def @res.read_body
1236
+ yield 'a' * 10
1237
+ raise EOFError
1238
+ end
1239
+
1240
+ e = assert_raises Mechanize::ChunkedTerminationError do
1241
+ @agent.response_read @res, @req, @uri
1242
+ end
1243
+
1244
+ assert_equal 'aaaaaaaaaa', e.body_io.read
1245
+ end
1246
+
1171
1247
  def test_response_read_content_length_head
1172
1248
  req = Net::HTTP::Head.new '/'
1173
1249
 
@@ -1239,21 +1315,6 @@ class TestMechanizeHttpAgent < Mechanize::TestCase
1239
1315
  end
1240
1316
  end
1241
1317
 
1242
- def test_file_response_content_type
1243
- Tempfile.open ['pi','.nothtml'] do |tempfile|
1244
- res = Mechanize::FileResponse.new tempfile.path
1245
- assert_equal nil, res['content-type']
1246
- end
1247
- Tempfile.open ['pi','.xhtml'] do |tempfile|
1248
- res = Mechanize::FileResponse.new tempfile.path
1249
- assert_equal 'text/html', res['content-type']
1250
- end
1251
- Tempfile.open ['pi','.html'] do |tempfile|
1252
- res = Mechanize::FileResponse.new tempfile.path
1253
- assert_equal 'text/html', res['Content-Type']
1254
- end
1255
- end
1256
-
1257
1318
  def test_response_read_large
1258
1319
  @agent.max_file_buffer = 10240
1259
1320
 
@@ -1310,20 +1371,37 @@ class TestMechanizeHttpAgent < Mechanize::TestCase
1310
1371
 
1311
1372
  page = fake_page
1312
1373
  page = @agent.response_redirect({ 'Location' => '/index.html' }, :get,
1313
- page, 0, referer)
1374
+ page, 0, {}, referer)
1314
1375
 
1315
1376
  assert_equal URI('http://fake.example/index.html'), page.uri
1316
1377
 
1317
1378
  assert_equal 'http://example/referer', requests.first['Referer']
1318
1379
  end
1319
1380
 
1381
+ def test_response_redirect_header
1382
+ @agent.redirect_ok = true
1383
+ referer = page 'http://example/referer'
1384
+
1385
+ headers = {
1386
+ 'Range' => 'bytes=0-9999',
1387
+ }
1388
+
1389
+ page = fake_page
1390
+ page = @agent.response_redirect({ 'Location' => '/http_headers' }, :get,
1391
+ page, 0, headers, referer)
1392
+
1393
+ assert_equal URI('http://fake.example/http_headers'), page.uri
1394
+
1395
+ assert_match 'range|bytes=0-999', page.body
1396
+ end
1397
+
1320
1398
  def test_response_redirect_malformed
1321
1399
  @agent.redirect_ok = true
1322
1400
  referer = page 'http://example/referer'
1323
1401
 
1324
1402
  page = fake_page
1325
1403
  page = @agent.response_redirect({ 'Location' => '/index.html?q=あ' }, :get,
1326
- page, 0, referer)
1404
+ page, 0, {}, referer)
1327
1405
 
1328
1406
  assert_equal URI('http://fake.example/index.html?q=%E3%81%82'), page.uri
1329
1407