httpclient 2.3.0 → 2.3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/httpclient/http.rb +15 -23
- data/lib/httpclient/util.rb +4 -0
- data/lib/httpclient/version.rb +1 -1
- data/test/test_httpclient.rb +14 -21
- metadata +4 -4
data/lib/httpclient/http.rb
CHANGED
@@ -542,7 +542,7 @@ module HTTP
|
|
542
542
|
# bear in mind that server may not support it. at least ruby's CGI doesn't.
|
543
543
|
@body = body
|
544
544
|
remember_pos(@body)
|
545
|
-
@size =
|
545
|
+
@size = body.respond_to?(:size) ? body.size - body.pos : nil
|
546
546
|
elsif boundary and Message.multiparam_query?(body)
|
547
547
|
@body = build_query_multipart_str(body, boundary)
|
548
548
|
@size = @body.size
|
@@ -554,45 +554,27 @@ module HTTP
|
|
554
554
|
|
555
555
|
def remember_pos(io)
|
556
556
|
# IO may not support it (ex. IO.pipe)
|
557
|
-
@positions[io] = io.pos
|
557
|
+
@positions[io] = io.pos if io.respond_to?(:pos)
|
558
558
|
end
|
559
559
|
|
560
560
|
def reset_pos(io)
|
561
|
-
io.pos = @positions[io] if @positions
|
561
|
+
io.pos = @positions[io] if @positions.key?(io)
|
562
562
|
end
|
563
563
|
|
564
564
|
def dump_file(io, dev)
|
565
|
-
return dump_file_length(io, @size, dev) if @size
|
566
565
|
buf = ''
|
567
566
|
while !io.read(@chunk_size, buf).nil?
|
568
567
|
dev << buf
|
569
568
|
end
|
570
569
|
end
|
571
570
|
|
572
|
-
def dump_file_length(io, size, dev)
|
573
|
-
buf = ''
|
574
|
-
while size > 0 && !(read = io.read(size > @chunk_size ? @chunk_size : size, buf)).nil?
|
575
|
-
dev << buf
|
576
|
-
size -= read.bytesize
|
577
|
-
end
|
578
|
-
end
|
579
|
-
|
580
571
|
def dump_chunks(io, dev)
|
581
|
-
return dump_chunks_length(io, io.size, dev) if io.respond_to?(:size) && io.size
|
582
572
|
buf = ''
|
583
573
|
while !io.read(@chunk_size, buf).nil?
|
584
574
|
dev << dump_chunk(buf)
|
585
575
|
end
|
586
576
|
end
|
587
577
|
|
588
|
-
def dump_chunks_length(io, size, dev)
|
589
|
-
buf = ''
|
590
|
-
while size > 0 && !(read = io.read(size > @chunk_size ? @chunk_size : size, buf)).nil?
|
591
|
-
dev << dump_chunk(buf)
|
592
|
-
size -= read.bytesize
|
593
|
-
end
|
594
|
-
end
|
595
|
-
|
596
578
|
def dump_chunk(str)
|
597
579
|
dump_chunk_size(str.bytesize) + (str + CRLF)
|
598
580
|
end
|
@@ -618,8 +600,18 @@ module HTTP
|
|
618
600
|
if Message.file?(part)
|
619
601
|
@as_stream = true
|
620
602
|
@body << part
|
621
|
-
|
622
|
-
|
603
|
+
if part.respond_to?(:lstat)
|
604
|
+
@size += part.lstat.size
|
605
|
+
elsif part.respond_to?(:size)
|
606
|
+
if sz = part.size
|
607
|
+
@size += sz
|
608
|
+
else
|
609
|
+
@size = nil
|
610
|
+
end
|
611
|
+
else
|
612
|
+
# use chunked upload
|
613
|
+
@size = nil
|
614
|
+
end
|
623
615
|
elsif @body[-1].is_a?(String)
|
624
616
|
@body[-1] += part.to_s
|
625
617
|
@size += part.to_s.bytesize if @size
|
data/lib/httpclient/util.rb
CHANGED
@@ -23,6 +23,10 @@ class HTTPClient
|
|
23
23
|
require 'uri'
|
24
24
|
begin
|
25
25
|
require 'addressable/uri'
|
26
|
+
# Older versions doesn't have #default_port
|
27
|
+
unless Addressable::URI.instance_methods.include?(:default_port) # 1.9 only
|
28
|
+
raise LoadError
|
29
|
+
end
|
26
30
|
class AddressableURI < Addressable::URI
|
27
31
|
# Overwrites the original definition just for one line...
|
28
32
|
def authority
|
data/lib/httpclient/version.rb
CHANGED
data/test/test_httpclient.rb
CHANGED
@@ -748,6 +748,19 @@ EOS
|
|
748
748
|
end
|
749
749
|
end
|
750
750
|
|
751
|
+
def test_post_with_file_without_size
|
752
|
+
STDOUT.sync = true
|
753
|
+
File.open(__FILE__) do |file|
|
754
|
+
def file.size
|
755
|
+
# Simulates some strange Windows behaviour
|
756
|
+
raise SystemCallError.new "Unknown Error (20047)"
|
757
|
+
end
|
758
|
+
assert_nothing_raised do
|
759
|
+
@client.post(serverurl + 'servlet', {1=>2, 3=>file})
|
760
|
+
end
|
761
|
+
end
|
762
|
+
end
|
763
|
+
|
751
764
|
def test_post_with_io # streaming, but not chunked
|
752
765
|
myio = StringIO.new("X" * (HTTP::Message::Body::DEFAULT_CHUNK_SIZE + 1))
|
753
766
|
def myio.read(*args)
|
@@ -764,7 +777,7 @@ EOS
|
|
764
777
|
assert_match(/\r\n2\r\n/m, res.content)
|
765
778
|
assert_match(/\r\nContent-Disposition: form-data; name="3"; filename=""\r\n/m, res.content)
|
766
779
|
assert_match(/\r\nContent-Length:/m, str.string)
|
767
|
-
assert_equal(
|
780
|
+
assert_equal(3, myio.called)
|
768
781
|
end
|
769
782
|
|
770
783
|
def test_post_with_io_nosize # streaming + chunked post
|
@@ -781,26 +794,6 @@ EOS
|
|
781
794
|
assert_match(/\r\nTransfer-Encoding: chunked\r\n/m, str.string)
|
782
795
|
end
|
783
796
|
|
784
|
-
def test_post_with_sized_io
|
785
|
-
myio = StringIO.new("45")
|
786
|
-
def myio.size
|
787
|
-
1
|
788
|
-
end
|
789
|
-
@client.debug_dev = str = StringIO.new
|
790
|
-
res = @client.post(serverurl + 'servlet', myio)
|
791
|
-
assert_match(/\r\n4\n/, str.string, 'should send "4" not "45"')
|
792
|
-
end
|
793
|
-
|
794
|
-
def test_post_with_sized_io_chunked
|
795
|
-
myio = StringIO.new("45")
|
796
|
-
def myio.size
|
797
|
-
1
|
798
|
-
end
|
799
|
-
@client.debug_dev = str = StringIO.new
|
800
|
-
res = @client.post(serverurl + 'servlet', {:file => myio})
|
801
|
-
assert_match(/\r\n4\r\n/, str.string, 'should send "4" not "45"')
|
802
|
-
end
|
803
|
-
|
804
797
|
def test_post_async
|
805
798
|
param = {'1'=>'2', '3'=>'4'}
|
806
799
|
conn = @client.post_async(serverurl + 'servlet', param)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httpclient
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.0
|
4
|
+
version: 2.3.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-11 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email: nahi@ruby-lang.org
|
@@ -90,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
90
|
version: '0'
|
91
91
|
segments:
|
92
92
|
- 0
|
93
|
-
hash:
|
93
|
+
hash: 926508888754393425
|
94
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
96
96
|
requirements:
|
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
99
|
version: '0'
|
100
100
|
segments:
|
101
101
|
- 0
|
102
|
-
hash:
|
102
|
+
hash: 926508888754393425
|
103
103
|
requirements: []
|
104
104
|
rubyforge_project:
|
105
105
|
rubygems_version: 1.8.23
|