http_spew 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,5 +1,35 @@
1
1
  ChangeLog from http://bogomips.org/http_spew.git
2
2
 
3
+ commit b53bbc7852d9788099e514b54a0b90d82a3338bb
4
+ Author: Eric Wong <normalperson@yhbt.net>
5
+ Date: Wed May 11 23:25:49 2011 +0000
6
+
7
+ http_spew 0.3.0 - ContentMD5 improvements
8
+
9
+ There are minor changes to HTTP_Spew::ContentMD5:
10
+ * allow optional input param to initialize
11
+ * update bytes_digested for incomplete xfers
12
+
13
+ Still not API-stable, but maybe it's closer...
14
+
15
+ commit 9d42089445aa2b61a50bf9a57a6f839569f4a1d4
16
+ Author: Eric Wong <normalperson@yhbt.net>
17
+ Date: Wed May 11 21:05:04 2011 +0000
18
+
19
+ content_md5: update bytes_digested for incomplete xfers
20
+
21
+ Being able to track progress is good.
22
+
23
+ commit 1a71f9204211061460e05e92c5523744b9b18afb
24
+ Author: Eric Wong <normalperson@yhbt.net>
25
+ Date: Wed May 11 20:08:20 2011 +0000
26
+
27
+ content_md5: optional input param to initialize
28
+
29
+ This allows users to specify an alternate input without
30
+ modifying the Rack +env+. This is potentially useful for
31
+ chaining other filters.
32
+
3
33
  commit 84eaf4df3da4ef55e21649b971f2f246ab556b52
4
34
  Author: Eric Wong <normalperson@yhbt.net>
5
35
  Date: Tue May 10 14:40:53 2011 -0700
data/GIT-VERSION-FILE CHANGED
@@ -1 +1 @@
1
- GIT_VERSION = 0.2.0
1
+ GIT_VERSION = 0.3.0
data/GIT-VERSION-GEN CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/bin/sh
2
2
 
3
3
  GVF=GIT-VERSION-FILE
4
- DEF_VER=v0.2.0.GIT
4
+ DEF_VER=v0.3.0.GIT
5
5
 
6
6
  LF='
7
7
  '
data/LATEST CHANGED
@@ -1,7 +1,8 @@
1
- === http_spew 0.2.0 - bugfixes and improvements / 2011-05-10 22:19 UTC
1
+ === http_spew 0.3.0 - ContentMD5 improvements / 2011-05-11 23:29 UTC
2
2
 
3
- InputSpray may now be layered on top of ContentMD5 successfully.
4
- Improved multi-threading abilities and tests.
3
+ There are minor changes to HTTP_Spew::ContentMD5:
4
+ * allow optional input param to initialize
5
+ * update bytes_digested for incomplete xfers
5
6
 
6
- Do not consider the API remotely stable, yet.
7
+ Still not API-stable, but maybe it's closer...
7
8
 
data/NEWS CHANGED
@@ -1,3 +1,11 @@
1
+ === http_spew 0.3.0 - ContentMD5 improvements / 2011-05-11 23:29 UTC
2
+
3
+ There are minor changes to HTTP_Spew::ContentMD5:
4
+ * allow optional input param to initialize
5
+ * update bytes_digested for incomplete xfers
6
+
7
+ Still not API-stable, but maybe it's closer...
8
+
1
9
  === http_spew 0.2.0 - bugfixes and improvements / 2011-05-10 22:19 UTC
2
10
 
3
11
  InputSpray may now be layered on top of ContentMD5 successfully.
@@ -9,7 +9,7 @@ class HTTP_Spew::ContentMD5
9
9
 
10
10
  CRLF = "\r\n" # :nodoc:
11
11
 
12
- def initialize(env)
12
+ def initialize(env, input = env["rack.input"])
13
13
  if trailer = env["HTTP_TRAILER"]
14
14
  unless trailer.split(/\s*,\s*/).grep(/\AContent-MD5\z/i)[0]
15
15
  trailer << (trailer.empty? ? "Content-MD5" : ",Content-MD5")
@@ -21,7 +21,7 @@ class HTTP_Spew::ContentMD5
21
21
  @to_io, wr = HTTP_Spew::ChunkyPipe.new
22
22
  expect_md5 = env.delete("HTTP_CONTENT_MD5")
23
23
  expect_len = env.delete("CONTENT_LENGTH")
24
- start_write_driver(env["rack.input"], wr, expect_md5, expect_len)
24
+ start_write_driver(input, wr, expect_md5, expect_len)
25
25
  end
26
26
 
27
27
  # compatible with IO#read and Rack::InputWrapper#read
@@ -34,18 +34,19 @@ class HTTP_Spew::ContentMD5
34
34
  Thread.new do
35
35
  begin
36
36
  digest = Digest::MD5.new
37
- buf = ""
38
- bytes = 0
39
- while input.read(0x4000, buf)
40
- n = buf.size
41
- bytes += n
42
- wr.write("#{n.to_s(16)}\r\n")
43
- digest.update(buf)
44
- wr.write(buf << CRLF)
37
+ @bytes_digested = 0
38
+ if buf = input.read(0x4000)
39
+ begin
40
+ n = buf.size
41
+ @bytes_digested += n
42
+ wr.write("#{n.to_s(16)}\r\n")
43
+ digest.update(buf)
44
+ wr.write(buf << CRLF)
45
+ end while input.read(0x4000, buf)
45
46
  end
46
- if expect_len && expect_len.to_i != bytes
47
+ if expect_len && expect_len.to_i != @bytes_digested
47
48
  raise HTTP_Spew::LengthError,
48
- "expect=#{expect_len} != got=#{bytes}", []
49
+ "expect=#{expect_len} != got=#@bytes_digested", []
49
50
  end
50
51
  md5 = [ digest.digest ].pack("m0")
51
52
  if expect_md5 && expect_md5.strip != md5
@@ -54,7 +55,6 @@ class HTTP_Spew::ContentMD5
54
55
  end
55
56
  wr.write "0\r\nContent-MD5: #{md5}\r\n\r\n"
56
57
  @content_md5 = md5
57
- @bytes_digested = bytes
58
58
  rescue => e
59
59
  @to_io.error = e
60
60
  ensure
@@ -1,2 +1,2 @@
1
1
  # -*- encoding: binary -*-
2
- HTTP_Spew.const_set :VERSION, "0.2.0"
2
+ HTTP_Spew.const_set :VERSION, "0.3.0"
@@ -83,4 +83,23 @@ class TestContentMD5 < Test::Unit::TestCase
83
83
  body = ""
84
84
  req.each { |buf| body << buf }
85
85
  end
86
+
87
+ def test_upload_with_md5_alt_input
88
+ str = rand_data(123) * (8 * 1021 * 13)
89
+ expect_md5 = [Digest::MD5.digest(str)].pack("m0")
90
+ expect = "expect=#{expect_md5}\nreaded=#{expect_md5}\n"
91
+ @env["CONTENT_LENGTH"] = str.size.to_s
92
+ @env["rack.input"] = File.open("/dev/null", "rb")
93
+ input = HTTP_Spew::ContentMD5.new(@env, StringIO.new(str))
94
+ assert_nil @env["CONTENT_LENGTH"]
95
+ assert_equal "chunked", @env["HTTP_TRANSFER_ENCODING"]
96
+ req = HTTP_Spew::Request.new(@env, input, @sockaddr)
97
+ rv = HTTP_Spew.wait 1, [req], 666
98
+ assert_equal 200, rv[0].response[0].to_i
99
+ body = ""
100
+ req.each { |buf| body << buf }
101
+ assert_equal body, expect
102
+ assert_equal expect_md5, input.content_md5
103
+ assert_equal 123 * 8 * 1021 * 13, input.bytes_digested
104
+ end
86
105
  end
@@ -69,7 +69,7 @@ class TestInputSprayWithMD5 < Test::Unit::TestCase
69
69
  assert_kind_of HTTP_Spew::ChecksumError, r.error
70
70
  }
71
71
  assert_nil input.content_md5
72
- assert_nil input.bytes_digested
72
+ assert_equal str.size, input.bytes_digested
73
73
  end
74
74
 
75
75
  def test_upload_with_valid_md5_sprayed_one_failure
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_spew
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - HTTP Spew hackers
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-10 00:00:00 Z
18
+ date: 2011-05-11 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: kcar