cae-multipart_parser 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cae/multipart_parser/parser.rb +3 -5
- data/lib/cae/multipart_parser/part.rb +4 -3
- data/lib/cae/multipart_parser/version.rb +1 -1
- data/spec/part_spec.rb +7 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58b85fbc0eb96b1b5d3d124d74b726df472fb1ed
|
4
|
+
data.tar.gz: 34cf8eabe80ace9e5df827b27b1355cd377d0e2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ec5356efc56b49734c768631fda770bf8e51dd3aa6edd60cc9fa4d24bd604ba077fdac53268e86e398e1215e84415603fc54f750932f0ecf722989bf06824bd
|
7
|
+
data.tar.gz: 39a4915b557153bd5f39630471d2a03b29b58e496cf7ca7fdbadbabe8f7d9b001baa8e48dd018b99389baaade121731e575fc715e709e29936bd60cbc8fbf2af
|
@@ -12,6 +12,8 @@ module Cae
|
|
12
12
|
|
13
13
|
ContentLengthUnsetError = Class.new(StandardError)
|
14
14
|
|
15
|
+
ParseError = Class.new(StandardError)
|
16
|
+
|
15
17
|
attr_accessor :read_buffer_size
|
16
18
|
|
17
19
|
def initialize(opts = {})
|
@@ -39,13 +41,9 @@ module Cae
|
|
39
41
|
i = 0
|
40
42
|
data_start = 0
|
41
43
|
|
42
|
-
#p "parsing #{length} chars: #{buffer}"
|
43
|
-
|
44
44
|
while i < length
|
45
45
|
c = buffer[i]
|
46
46
|
|
47
|
-
#p "state=#{@state}: i=#{i}. index=#{@index}, d_start=#{data_start} chars=#{buffer[i, 50]}"
|
48
|
-
|
49
47
|
case @state
|
50
48
|
when :start
|
51
49
|
if @index == @boundary_length - 2
|
@@ -150,7 +148,7 @@ module Cae
|
|
150
148
|
end # while
|
151
149
|
|
152
150
|
if i != length
|
153
|
-
raise "unexpected char at #{i} (#{
|
151
|
+
raise ParseError, "unexpected char at char #{parsed+i} (#{c.inspect})"
|
154
152
|
end
|
155
153
|
|
156
154
|
parsed += length
|
@@ -18,8 +18,9 @@ module Cae
|
|
18
18
|
str.split(/\r\n/).each do |h|
|
19
19
|
key, value = h.split ':'
|
20
20
|
|
21
|
-
# normalize content-length ->
|
22
|
-
key
|
21
|
+
# normalize content-length -> CONTENT_LENGTH
|
22
|
+
key.upcase!
|
23
|
+
key.tr! '-', '_'
|
23
24
|
|
24
25
|
@headers[key] = value.lstrip
|
25
26
|
end
|
@@ -27,7 +28,7 @@ module Cae
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def content_length
|
30
|
-
@headers['
|
31
|
+
@headers['CONTENT_LENGTH'].to_i
|
31
32
|
end
|
32
33
|
|
33
34
|
def on(event, &callback)
|
data/spec/part_spec.rb
CHANGED
@@ -9,37 +9,37 @@ describe Cae::MultipartParser::Part do
|
|
9
9
|
it "parses a simple input" do
|
10
10
|
input = "Content-Type: text/html"
|
11
11
|
part.parse_header_str(input).must_equal({
|
12
|
-
'
|
12
|
+
'CONTENT_TYPE' => 'text/html'
|
13
13
|
})
|
14
14
|
end
|
15
15
|
|
16
16
|
it "ignores trailing CRLF" do
|
17
17
|
input = "Content-Type: text/html\r\n"
|
18
18
|
part.parse_header_str(input).must_equal({
|
19
|
-
'
|
19
|
+
'CONTENT_TYPE' => 'text/html'
|
20
20
|
})
|
21
21
|
end
|
22
22
|
|
23
23
|
it "parses multiple lines" do
|
24
24
|
input = "Content-Type: text/html\r\nContent-Length: 100"
|
25
25
|
part.parse_header_str(input).must_equal({
|
26
|
-
'
|
27
|
-
'
|
26
|
+
'CONTENT_TYPE' => 'text/html',
|
27
|
+
'CONTENT_LENGTH' => '100'
|
28
28
|
})
|
29
29
|
end
|
30
30
|
|
31
31
|
it "parses multiline headers" do
|
32
32
|
input = "Content-Type: multipart/form-data;\r\n\tboundary=foo"
|
33
33
|
part.parse_header_str(input).must_equal({
|
34
|
-
'
|
34
|
+
'CONTENT_TYPE' => 'multipart/form-data; boundary=foo'
|
35
35
|
})
|
36
36
|
end
|
37
37
|
|
38
38
|
it "parses multiple multiline headers" do
|
39
39
|
input = "Content-Type: multipart/form-data;\r\n\tboundary=foo\r\nContent-Type2: multipart/form-data;\r\n\tboundary=bar"
|
40
40
|
part.parse_header_str(input).must_equal({
|
41
|
-
'
|
42
|
-
'
|
41
|
+
'CONTENT_TYPE' => 'multipart/form-data; boundary=foo',
|
42
|
+
'CONTENT_TYPE2' => 'multipart/form-data; boundary=bar'
|
43
43
|
})
|
44
44
|
end
|
45
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cae-multipart_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Elsworth
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multipart-post
|