cae-multipart_parser 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b40160cadbf8cc8a3f697358faf9fbc86189f69a
4
- data.tar.gz: 9c53814388b57e07c4fe9067f1bcac1c642d5498
3
+ metadata.gz: 58b85fbc0eb96b1b5d3d124d74b726df472fb1ed
4
+ data.tar.gz: 34cf8eabe80ace9e5df827b27b1355cd377d0e2d
5
5
  SHA512:
6
- metadata.gz: 01ed9067615cf6c444f92558b6d6232ff3b431afbd09264fbc5348f1a83183cb7e8c20d3b095f0e825fad8c1c788c12b19719cf554fa57232227693e3181c47b
7
- data.tar.gz: 9cd5bf6885f0a60098497089797c9dc0345279a2458d69b8f11e198662f70d084af9a8bd9ca522a73e35e63881db17f38ee462564710050fd535fac6e8905d88
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} (#{buffer[i].inspect})"
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 -> Content-Length
22
- key = key.split('-').map(&:capitalize).join('-')
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['Content-Length'].to_i
31
+ @headers['CONTENT_LENGTH'].to_i
31
32
  end
32
33
 
33
34
  def on(event, &callback)
@@ -1,5 +1,5 @@
1
1
  module Cae
2
2
  module MultipartParser
3
- VERSION = "1.0.0"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
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
- 'Content-Type' => 'text/html'
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
- 'Content-Type' => 'text/html'
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
- 'Content-Type' => 'text/html',
27
- 'Content-Length' => '100'
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
- 'Content-Type' => 'multipart/form-data; boundary=foo'
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
- 'Content-Type' => 'multipart/form-data; boundary=foo',
42
- 'Content-Type2' => 'multipart/form-data; boundary=bar'
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.0.0
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-03 00:00:00.000000000 Z
11
+ date: 2015-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multipart-post