kcar 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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/README CHANGED
@@ -83,7 +83,7 @@ don't email the git mailing list or maintainer with kcar patches.
83
83
  == Contact
84
84
 
85
85
  All feedback (bug reports, user/development discussion, patches, pull
86
- requests) go to the mailing list: mailto:kcar@librelist.com
86
+ requests) go to the mailing list: mailto:kcar@librelist.org
87
87
 
88
88
  The mailing list is mirrored to Gmane, all information about the
89
89
  group is here:
data/TODO CHANGED
@@ -1,2 +1,2 @@
1
- Patches to kcar@librelist.com (via git format-patch + git send-email) for
1
+ Patches to kcar@librelist.org (via git format-patch + git send-email) for
2
2
  these would be greatly appreciated
@@ -70,12 +70,27 @@ struct http_parser {
70
70
  #define MARK(M,FPC) (hp->M = (FPC) - buffer)
71
71
  #define PTR_TO(F) (buffer + hp->F)
72
72
  #define STR_NEW(M,FPC) rb_str_new(PTR_TO(M), LEN(M, FPC))
73
+ #define STRIPPED_STR_NEW(M,FPC) stripped_str_new(PTR_TO(M), LEN(M, FPC))
73
74
 
74
75
  #define HP_FL_TEST(hp,fl) ((hp)->flags & (UH_FL_##fl))
75
76
  #define HP_FL_SET(hp,fl) ((hp)->flags |= (UH_FL_##fl))
76
77
  #define HP_FL_UNSET(hp,fl) ((hp)->flags &= ~(UH_FL_##fl))
77
78
  #define HP_FL_ALL(hp,fl) (HP_FL_TEST(hp, fl) == (UH_FL_##fl))
78
79
 
80
+ static int is_lws(char c)
81
+ {
82
+ return (c == ' ' || c == '\t');
83
+ }
84
+
85
+ static VALUE stripped_str_new(const char *str, long len)
86
+ {
87
+ long end;
88
+
89
+ for (end = len - 1; end >= 0 && is_lws(str[end]); end--);
90
+
91
+ return rb_str_new(str, end + 1);
92
+ }
93
+
79
94
  static void finalize_header(struct http_parser *hp)
80
95
  {
81
96
  if ((HP_FL_TEST(hp, HASTRAILER) && ! HP_FL_TEST(hp, CHUNKED)))
@@ -144,6 +159,9 @@ static void write_cont_value(struct http_parser *hp,
144
159
  char *buffer, const char *p)
145
160
  {
146
161
  char *vptr;
162
+ long end;
163
+ long len = LEN(mark, p);
164
+ long cont_len;
147
165
 
148
166
  if (hp->cont == Qfalse)
149
167
  rb_raise(eParserError, "invalid continuation line");
@@ -154,19 +172,24 @@ static void write_cont_value(struct http_parser *hp,
154
172
  assert(TYPE(hp->cont) == T_STRING && "continuation line is not a string");
155
173
  assert(hp->mark > 0 && "impossible continuation line offset");
156
174
 
157
- if (LEN(mark, p) == 0)
175
+ if (len == 0)
158
176
  return;
159
177
 
160
- if (RSTRING_LEN(hp->cont) > 0)
178
+ cont_len = RSTRING_LEN(hp->cont);
179
+ if (cont_len > 0) {
161
180
  --hp->mark;
181
+ len = LEN(mark, p);
182
+ }
162
183
 
163
184
  vptr = PTR_TO(mark);
164
185
 
165
- if (RSTRING_LEN(hp->cont) > 0) {
186
+ /* normalize tab to space */
187
+ if (cont_len > 0) {
166
188
  assert((' ' == *vptr || '\t' == *vptr) && "invalid leading white space");
167
189
  *vptr = ' ';
168
190
  }
169
- rb_str_buf_cat(hp->cont, vptr, LEN(mark, p));
191
+ for (end = len - 1; end >= 0 && is_lws(vptr[end]); end--);
192
+ rb_str_buf_cat(hp->cont, vptr, end + 1);
170
193
  }
171
194
 
172
195
  static void write_value(VALUE hdr, struct http_parser *hp,
@@ -192,7 +215,7 @@ static void write_value(VALUE hdr, struct http_parser *hp,
192
215
  VALIDATE_MAX_LENGTH(vlen, FIELD_VALUE);
193
216
  VALIDATE_MAX_LENGTH(flen, FIELD_NAME);
194
217
  f = rb_str_new(fptr, (long)flen);
195
- v = rb_str_new(vptr, (long)vlen);
218
+ v = stripped_str_new(vptr, (long)vlen);
196
219
 
197
220
  /* needs more tests for error-checking here */
198
221
  /*
@@ -602,6 +625,7 @@ static VALUE filter_body(VALUE self, VALUE buf, VALUE data)
602
625
  dlen = RSTRING_LEN(data);
603
626
 
604
627
  StringValue(buf);
628
+ rb_str_modify(buf);
605
629
  rb_str_resize(buf, dlen); /* we can never copy more than dlen bytes */
606
630
  OBJ_TAINT(buf); /* keep weirdo $SAFE users happy */
607
631
 
@@ -36,7 +36,7 @@
36
36
 
37
37
  value_cont = lws+ any* >start_value %write_cont_value;
38
38
 
39
- message_header = ((field_name ":" " "* field_value)|value_cont) :> CRLF;
39
+ message_header = ((field_name ":" lws* field_value)|value_cont) :> CRLF;
40
40
  chunk_ext_val = token*;
41
41
  chunk_ext_name = token*;
42
42
  chunk_extension = ( ";" " "* chunk_ext_name ("=" chunk_ext_val)? )*;
@@ -113,7 +113,7 @@ class Kcar::Response
113
113
  # in the response, we'll just yield a stringified version to our
114
114
  # server and pretend it's part of the body.
115
115
  trailers = @parser.extract_trailers(@hdr)
116
- yield(trailers.map! { |k,v| "#{k}: #{v}\r\n" }.join("") << CRLF)
116
+ yield(trailers.map! { |k,v| "#{k}: #{v}\r\n" }.join << CRLF)
117
117
  end
118
118
 
119
119
  def each_until_eof
data/pkg.mk CHANGED
@@ -69,7 +69,7 @@ doc:: .document .wrongdoc.yml $(pkg_extra)
69
69
  $(RM) -r doc
70
70
  $(WRONGDOC) all
71
71
  install -m644 COPYING doc/COPYING
72
- install -m644 $(shell grep '^[A-Z]' .document) doc/
72
+ install -m644 $(shell LC_ALL=C grep '^[A-Z]' .document) doc/
73
73
 
74
74
  ifneq ($(VERSION),)
75
75
  pkggem := pkg/$(rfpackage)-$(VERSION).gem
@@ -167,5 +167,9 @@ doc_gz: docs = $(shell find doc -type f ! -regex '^.*\.\(gif\|jpg\|png\|gz\)$$')
167
167
  doc_gz:
168
168
  for i in $(docs); do \
169
169
  gzip --rsyncable -9 < $$i > $$i.gz; touch -r $$i $$i.gz; done
170
+ check-warnings:
171
+ @(for i in $$(git ls-files '*.rb'| grep -v '^setup\.rb$$'); \
172
+ do $(RUBY) -d -W2 -c $$i; done) | grep -v '^Syntax OK$$' || :
170
173
 
171
174
  .PHONY: all .FORCE-GIT-VERSION-FILE doc test $(test_units) manifest
175
+ .PHONY: check-warnings
@@ -254,4 +254,39 @@ class TestParser < Test::Unit::TestCase
254
254
  end
255
255
  end
256
256
 
257
+ def test_leading_tab
258
+ resp = "HTTP/1.1 200 OK\r\nHost:\texample.com\r\n\r\n"
259
+ assert @hp.headers(env = {}, resp)
260
+ assert_equal 'example.com', env['Host']
261
+ end
262
+
263
+ def test_trailing_whitespace
264
+ resp = "HTTP/1.1 200 OK\r\nHost: example.com \r\n\r\n"
265
+ assert @hp.headers(env = {}, resp)
266
+ assert_equal 'example.com', env['Host']
267
+ end
268
+
269
+ def test_trailing_tab
270
+ resp = "HTTP/1.1 200 OK\r\nHost: example.com\t\r\n\r\n"
271
+ assert @hp.headers(env = {}, resp)
272
+ assert_equal 'example.com', env['Host']
273
+ end
274
+
275
+ def test_trailing_multiple_linear_whitespace
276
+ resp = "HTTP/1.1 200 OK\r\nHost: example.com\t \t \t\r\n\r\n"
277
+ assert @hp.headers(env = {}, resp)
278
+ assert_equal 'example.com', env['Host']
279
+ end
280
+
281
+ def test_embedded_linear_whitespace_ok
282
+ resp = "HTTP/1.1 200 OK\r\nX-Space: hello\t world\t \r\n\r\n"
283
+ assert @hp.headers(env = {}, resp)
284
+ assert_equal "hello\t world", env["X-Space"]
285
+ end
286
+
287
+ def test_empty_header
288
+ resp = "HTTP/1.1 200 OK\r\nHost: \r\n\r\n"
289
+ assert @hp.headers(env = {}, resp)
290
+ assert_equal '', env['Host']
291
+ end
257
292
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kcar
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
  - kcar hackers
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-24 00:00:00 +00:00
19
- default_executable:
18
+ date: 2011-06-07 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: wrongdoc
@@ -83,7 +82,6 @@ files:
83
82
  - setup.rb
84
83
  - test/test_parser.rb
85
84
  - test/test_response.rb
86
- has_rdoc: true
87
85
  homepage: http://bogomips.org/kcar/
88
86
  licenses: []
89
87
 
@@ -116,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
114
  requirements: []
117
115
 
118
116
  rubyforge_project: rainbows
119
- rubygems_version: 1.5.2
117
+ rubygems_version: 1.8.2
120
118
  signing_key:
121
119
  specification_version: 3
122
120
  summary: bytestream to Rack response converter