kcar 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,110 +1,73 @@
1
- ChangeLog from git://git.bogomips.org/kcar.git ()
1
+ ChangeLog from git://git.bogomips.org/kcar.git (v0.1.0..v0.1.1)
2
2
 
3
- commit aca587b1bcf544b0fbaf031edc476e1b155e0263
3
+ commit 2b264a464707e448275883ac198d7ead7eaeadb9
4
4
  Author: Eric Wong <normalperson@yhbt.net>
5
- Date: Wed Apr 28 15:14:36 2010 -0700
5
+ Date: Sat Jul 24 23:51:48 2010 +0000
6
6
 
7
- add TODO
8
-
9
- commit ee89a72720c8c035eebf2389e09dd28c788551d8
10
- Author: Eric Wong <normalperson@yhbt.net>
11
- Date: Wed Apr 28 15:12:19 2010 -0700
12
-
13
- autoload Kcar::Response, document VERSION constant
7
+ kcar 0.1.1
14
8
 
15
- Kcar::Response may not be useful for people that eventually use
16
- EventMachine or Rev.
17
-
18
- commit 8ddf88d1e9917baabc6c485546d1806c3a81cd0e
19
- Author: Eric Wong <normalperson@yhbt.net>
20
- Date: Wed Apr 28 15:10:38 2010 -0700
21
-
22
- kcar/parser: magic comments for binary encoding
9
+ Our handling of pipelined identity (not chunked) responses
10
+ did not properly reset our internal buffer, causing HTTP
11
+ header parsing to fail for the second response as the buffer
12
+ still contained the last part of the body from the previous
13
+ response.
23
14
 
24
- Any regexps or temporary strings should be created with binary
25
- encoding as that's how HTTP processing is done.
15
+ There are also minor documentation updates and cleanups.
26
16
 
27
- commit 1fdfb4a68591337be2a88dfb4021da6232361825
17
+ commit 558513bdeaac2bd1feb9df46c3ba09616b1be2bf
28
18
  Author: Eric Wong <normalperson@yhbt.net>
29
- Date: Wed Apr 28 15:08:05 2010 -0700
19
+ Date: Sat Jul 24 23:43:08 2010 +0000
30
20
 
31
- Update README with install and usage instructions
32
-
33
- commit 9d880bb373793f42c29cd77890663d62a1b9c578
34
- Author: Eric Wong <normalperson@yhbt.net>
35
- Date: Wed Apr 28 14:33:27 2010 -0700
36
-
37
- add Kcar::Response#rack to give proper Rack responses
21
+ response: simplify trailers handling
38
22
 
39
- We can't unchunk bodies and still say
40
- "Transfer-Encoding: chunked", nor can we say we have Trailers
41
- without chunked encoding. So we'll unconditionally disable
42
- unchunking and pass the response through as-is
43
-
44
- commit 2a3a8ac8e64f5f02f87de268c9b2615437d16a96
45
- Author: Eric Wong <normalperson@yhbt.net>
46
- Date: Wed Apr 28 13:09:51 2010 -0700
23
+ Kcar::Parser#extract_trailers never returns a false/nil
24
+ value, so there's no reason to check for it.
47
25
 
48
- kcar/response: rdoc public methods
49
-
50
- commit b75e162e0b9b605a9b3033c3dbc616afcb08b4ad
51
- Author: Eric Wong <normalperson@yhbt.net>
52
- Date: Wed Apr 28 12:58:29 2010 -0700
53
-
54
- Documentation prep for release
55
-
56
- commit b85f1528667b3aaa699b37dcc362901e1e573b04
26
+ commit 62621af7c8724f5cc5cc3a6dfcd47eb6654286a5
57
27
  Author: Eric Wong <normalperson@yhbt.net>
58
- Date: Wed Apr 28 12:48:18 2010 -0700
28
+ Date: Sat Jul 24 23:18:14 2010 +0000
59
29
 
60
- rename Kcar::Session => Kcar::Response
30
+ response: fix handling of pipelined identity responses
61
31
 
62
- It's not a real "session" since it does not have any facilities
63
- to write responses.
32
+ When parsing a stream of multiple responses (when HTTP
33
+ pipelining is enabled), we did not properly reset our
34
+ internal buffer, causing failures when parsing the
35
+ second response.
64
36
 
65
- commit dd84d98bce03e3da529c4b51d2eba761dda749e8
37
+ commit 35e3ad8134c39902b502e20d88246be2751767e1
66
38
  Author: Eric Wong <normalperson@yhbt.net>
67
- Date: Wed Apr 28 12:42:48 2010 -0700
68
-
69
- build + release infrastructure
39
+ Date: Sat Jul 24 21:38:40 2010 +0000
70
40
 
71
- commit e32c35bac78a7e7d8d711d360c143c9ebc64eed2
72
- Author: Eric Wong <normalperson@yhbt.net>
73
- Date: Tue Apr 27 11:39:06 2010 -0700
74
-
75
- parser: avoid shadowing "key" variable
41
+ response: fix unreferenced constant
42
+
43
+ Oops :x
76
44
 
77
- commit 8bcf07ce90a9813e3859dce97b4a3a07b43c9cea
45
+ commit 6224ff57ce2b95cd62ab01316dedcc106e6e4e6b
78
46
  Author: Eric Wong <normalperson@yhbt.net>
79
- Date: Tue Apr 27 11:33:32 2010 -0700
47
+ Date: Sat Jul 24 20:44:03 2010 +0000
80
48
 
81
- kcar.rl: more comments explaining write_value;
49
+ update README with Rubinius support
82
50
 
83
- This function can get intimidating to new users
51
+ It has likely always worked.
84
52
 
85
- commit 356435e60da0ffc92b4c7a9eb801255f094b4610
53
+ commit 856a8a7e061845d5db617cc407c92aabdb4679a0
86
54
  Author: Eric Wong <normalperson@yhbt.net>
87
- Date: Mon Apr 26 19:18:10 2010 -0700
55
+ Date: Sun May 2 16:38:27 2010 -0700
88
56
 
89
- ext: additional validations for valid HTTP responses
57
+ document Kcar::Parser#chunked? method
90
58
 
91
- commit 31bd370baef622aaa5dd14084f27baf2fabf506c
59
+ commit 7f1597ea01cac380393fb4d50e458204059beb24
92
60
  Author: Eric Wong <normalperson@yhbt.net>
93
- Date: Mon Apr 26 19:09:26 2010 -0700
61
+ Date: Sun May 2 16:30:13 2010 -0700
94
62
 
95
- ext: better document keepalive behavior
63
+ update README with Gmane and mbox archive info
96
64
 
97
- commit 6066e9f608460adf46b215a9b6e5f351a87ba4b0
65
+ commit 6b4bf45c0cab182462ed0c5c0d98fe11e1201b61
98
66
  Author: Eric Wong <normalperson@yhbt.net>
99
- Date: Mon Apr 26 19:02:41 2010 -0700
67
+ Date: Wed Apr 28 22:26:45 2010 +0000
100
68
 
101
- ext: remove dead code from Parser#filter_body
69
+ gemspec: fix authors and homepage info
102
70
 
103
- We avoid filter_body overhead for things with known
104
- content-length.
105
-
106
- commit f071a6f936ba0b22610b1f7ce68e414403f29996
107
- Author: Eric Wong <normalperson@yhbt.net>
108
- Date: Mon Apr 26 18:29:21 2010 -0700
109
-
110
- initial
71
+ Oops, URLs should end with a trailing slash since I'm expecting
72
+ my webserver to load index.html. Also, it's "kcar hackers",
73
+ kcar did not write itself!
data/GIT-VERSION-FILE CHANGED
@@ -1 +1 @@
1
- GIT_VERSION = 0.1.0
1
+ GIT_VERSION = 0.1.1
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.1.0.GIT
4
+ DEF_VER=v0.1.1.GIT
5
5
 
6
6
  LF='
7
7
  '
data/GNUmakefile CHANGED
@@ -54,7 +54,7 @@ NEWS: GIT-VERSION-FILE
54
54
  latest: NEWS
55
55
  @awk 'BEGIN{RS="=== ";ORS=""}NR==2{sub(/\n$$/,"");print RS""$$0 }' $<
56
56
 
57
- SINCE =
57
+ SINCE = 0.1.0
58
58
  ChangeLog: LOG_VERSION = \
59
59
  $(shell git rev-parse -q "$(GIT_VERSION)" >/dev/null 2>&1 && \
60
60
  echo $(GIT_VERSION) || git describe)
data/NEWS CHANGED
@@ -1,3 +1,13 @@
1
+ === 0.1.1 / 2010-07-25 00:03 UTC
2
+
3
+ Our handling of pipelined identity (not chunked) responses
4
+ did not properly reset our internal buffer, causing HTTP
5
+ header parsing to fail for the second response as the buffer
6
+ still contained the last part of the body from the previous
7
+ response.
8
+
9
+ There are also minor documentation updates and cleanups.
10
+
1
11
  === 0.1.0 / 2010-04-28 22:18 UTC
2
12
 
3
13
  initial
data/README CHANGED
@@ -19,6 +19,8 @@ A drop-in, Net::HTTP-compatible interface is planned.
19
19
  * streaming interface for response bodies allows for incremental
20
20
  processing of arbitrarily large responses.
21
21
 
22
+ * suppported under Ruby 1.8, 1.9 and Rubinuus
23
+
22
24
  == Problems
23
25
 
24
26
  * kcar is only lightly tested and is not yet aware of all quirks found in
@@ -84,3 +86,12 @@ don't email the git mailing list or maintainer with kcar patches.
84
86
 
85
87
  All feedback (bug reports, user/development discussion, patches, pull
86
88
  requests) go to the mailing list: mailto:kcar@librelist.com
89
+
90
+ The mailing list is mirrored to Gmane, all information about the
91
+ group is here:
92
+
93
+ http://gmane.org/info.php?group=gmane.comp.lang.ruby.kcar.general
94
+
95
+ Mailing list archives in mbox format may be downloaded here:
96
+
97
+ http://bogomips.org/kcar/archives/
data/ext/kcar/kcar.c CHANGED
@@ -1339,6 +1339,13 @@ static VALUE body_bytes_left(VALUE self)
1339
1339
  return Qnil;
1340
1340
  }
1341
1341
 
1342
+ /**
1343
+ * Document-method: chunked
1344
+ * call-seq:
1345
+ * parser.chunked? => true or false
1346
+ *
1347
+ * This is used to detect if a response uses chunked Transfer-Encoding or not.
1348
+ */
1342
1349
  static VALUE chunked(VALUE self)
1343
1350
  {
1344
1351
  struct http_parser *hp = data_get(self);
data/ext/kcar/kcar.rl CHANGED
@@ -467,6 +467,13 @@ static VALUE body_bytes_left(VALUE self)
467
467
  return Qnil;
468
468
  }
469
469
 
470
+ /**
471
+ * Document-method: chunked
472
+ * call-seq:
473
+ * parser.chunked? => true or false
474
+ *
475
+ * This is used to detect if a response uses chunked Transfer-Encoding or not.
476
+ */
470
477
  static VALUE chunked(VALUE self)
471
478
  {
472
479
  struct http_parser *hp = data_get(self);
data/kcar.gemspec CHANGED
@@ -7,8 +7,8 @@ Gem::Specification.new do |s|
7
7
  s.name = %q{kcar}
8
8
  s.version = ENV["VERSION"]
9
9
 
10
- s.homepage = 'http://bogomips.org/kcar'
11
- s.authors = ["kcar"]
10
+ s.homepage = 'http://bogomips.org/kcar/'
11
+ s.authors = ["kcar hackers"]
12
12
  s.date = Time.now.utc.strftime('%Y-%m-%d')
13
13
  s.description = description
14
14
  s.email = %q{kcar@librelist.com}
data/lib/kcar/response.rb CHANGED
@@ -107,9 +107,8 @@ class Response < Struct.new(:sock, :hdr, :unchunk, :buf, :parser)
107
107
  # since Rack does not provide a way to explicitly send trailers
108
108
  # in the response, we'll just yield a stringified version to our
109
109
  # server and pretend it's part of the body.
110
- if trailers = parser.extract_trailers(hdr)
111
- yield(trailers.map! { |k,v| "#{k}: #{v}\r\n" }.join("") << "\r\n")
112
- end
110
+ trailers = parser.extract_trailers(hdr)
111
+ yield(trailers.map! { |k,v| "#{k}: #{v}\r\n" }.join("") << CRLF)
113
112
  end
114
113
 
115
114
  def each_until_eof(&block)
@@ -140,9 +139,13 @@ class Response < Struct.new(:sock, :hdr, :unchunk, :buf, :parser)
140
139
  len -= dst.size
141
140
  yield dst
142
141
  end
143
- while len > 0
144
- len -= sock.readpartial(len > READ_SIZE ? CHUNK_SIZE : len, dst).size
145
- yield dst
142
+
143
+ if len > 0
144
+ begin
145
+ len -= sock.readpartial(len > READ_SIZE ? READ_SIZE : len, dst).size
146
+ yield dst
147
+ end while len > 0
148
+ dst.respond_to?(:clear) ? dst.clear : self.buf = ''
146
149
  end
147
150
  end
148
151
  end
data/lib/kcar.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # -*- encoding: binary -*-
2
2
  module Kcar
3
3
 
4
- # current version, currently 0.1.0
5
- VERSION = '0.1.0'
4
+ # current version, currently 0.1.1
5
+ VERSION = '0.1.1'
6
6
 
7
7
  autoload :Response, 'kcar/response'
8
8
  end
@@ -3,12 +3,75 @@ require 'test/unit'
3
3
  require 'pp'
4
4
  require 'socket'
5
5
  require 'kcar'
6
+ require 'digest/sha1'
6
7
 
7
8
  class TestSession < Test::Unit::TestCase
8
9
  def setup
9
10
  @s, @c = UNIXSocket.pair
10
11
  end
11
12
 
13
+ def test_http_small_pipelined_identity
14
+ resp = "HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nhello world\n" \
15
+ "HTTP/1.1 200 OK\r\nContent-Length: 14\r\n\r\ngoodbye world\n"
16
+ pid = fork do
17
+ @s << resp
18
+ @s.close
19
+ end
20
+ @s.close
21
+ @response = Kcar::Response.new(@c)
22
+ status, headers, body = @response.rack
23
+ assert_equal status, "200 OK"
24
+ assert_equal({'Content-Length'=>'12'},headers)
25
+ tmp = []
26
+ assert_nothing_raised { body.each { |chunk| tmp << chunk.dup } }
27
+ assert_equal [ "hello world\n" ], tmp
28
+ body.close
29
+ assert ! @c.closed?
30
+
31
+ status, headers, body = @response.rack
32
+ assert_equal status, "200 OK"
33
+ assert_equal({'Content-Length'=>'14'},headers)
34
+ tmp = []
35
+ assert_nothing_raised { body.each { |chunk| tmp << chunk.dup } }
36
+ assert_equal [ "goodbye world\n" ], tmp
37
+
38
+ _, status = Process.waitpid2(pid)
39
+ assert status.success?
40
+ body.close
41
+ end
42
+
43
+ def test_http_big_pipelined_identity
44
+ nr = 1024 * 512
45
+ width = 80
46
+ length = nr * width
47
+ template = "%0#{width - 1}x\n"
48
+ expect = Digest::SHA1.new
49
+ nr.times { |i| expect << sprintf(template, i) }
50
+ pid = fork do
51
+ @s.sync = false
52
+ @s << "HTTP/1.1 200 OK\r\nContent-Length: #{length}\r\n\r\n"
53
+ nr.times { |i| @s.printf(template, i) }
54
+ @s << "HTTP/1.1 200 OK\r\nContent-Length: #{length}\r\n\r\n"
55
+ nr.times { |i| @s.printf(template, i) }
56
+ @s.close
57
+ end
58
+ @s.close
59
+ @response = Kcar::Response.new(@c)
60
+
61
+ 2.times do |i|
62
+ status, headers, body = @response.rack
63
+ assert_equal status, "200 OK"
64
+ assert_equal({'Content-Length'=>length.to_s}, headers)
65
+ sha1 = Digest::SHA1.new
66
+ assert_nothing_raised { body.each { |chunk| sha1 << chunk } }
67
+ assert_equal expect, sha1, "#{expect.hexdigest} != #{sha1.hexdigest}"
68
+ body.close
69
+ assert ! @c.closed?
70
+ end
71
+ _, status = Process.waitpid2(pid)
72
+ assert status.success?
73
+ end
74
+
12
75
  def test_http_one_zero
13
76
  pid = fork do
14
77
  @s << "HTTP/1.0 200 OK\r\n\r\nHI"
metadata CHANGED
@@ -1,15 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kcar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
5
11
  platform: ruby
6
12
  authors:
7
- - kcar
13
+ - kcar hackers
8
14
  autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-04-28 00:00:00 +00:00
18
+ date: 2010-07-25 00:00:00 +00:00
13
19
  default_executable:
14
20
  dependencies: []
15
21
 
@@ -61,7 +67,7 @@ files:
61
67
  - test/test_parser.rb
62
68
  - test/test_response.rb
63
69
  has_rdoc: true
64
- homepage: http://bogomips.org/kcar
70
+ homepage: http://bogomips.org/kcar/
65
71
  licenses: []
66
72
 
67
73
  post_install_message:
@@ -73,21 +79,27 @@ require_paths:
73
79
  - lib
74
80
  - ext
75
81
  required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
76
83
  requirements:
77
84
  - - ">="
78
85
  - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
79
89
  version: "0"
80
- version:
81
90
  required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
82
92
  requirements:
83
93
  - - ">="
84
94
  - !ruby/object:Gem::Version
95
+ hash: 3
96
+ segments:
97
+ - 0
85
98
  version: "0"
86
- version:
87
99
  requirements: []
88
100
 
89
101
  rubyforge_project: rainbows
90
- rubygems_version: 1.3.5
102
+ rubygems_version: 1.3.7
91
103
  signing_key:
92
104
  specification_version: 3
93
105
  summary: bytestream to Rack response converter