segregate 0.3.0 → 0.3.1
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 +4 -4
- data/README.md +3 -3
- data/lib/segregate/version.rb +1 -1
- data/lib/segregate.rb +0 -8
- data/spec/segregate_spec.rb +12 -24
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96b4059a490bf0c58abeae11ab8c0540799a7ec6
|
4
|
+
data.tar.gz: c1f1e6da2dc72b17051991272f1ddc34b9ef6737
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e10f62346236a7a67782334697c5ee1c9d796c2b4187d29970e277a2aac414bd7c7fe679efefc97bfd00740db0c420e9295dab648bd9188e850f159e742faf4
|
7
|
+
data.tar.gz: 3edd3f5888ce6a106ef259d4eb662ac4a5823cd0a126c21c1ce3c96d878e29da30a145d1135d555258b72c9e85abe7235c9c0f2b1b1ee0c9f5842331406b6c2d
|
data/README.md
CHANGED
@@ -33,7 +33,7 @@ Require Segregate at the start of your code
|
|
33
33
|
require 'segregate'
|
34
34
|
```
|
35
35
|
|
36
|
-
### Basic
|
36
|
+
### Basic usage
|
37
37
|
#### Parsing data:
|
38
38
|
|
39
39
|
```ruby
|
@@ -81,7 +81,7 @@ parser.headers['accept'] = "application/json"
|
|
81
81
|
parser.body.sub! "data", "information"
|
82
82
|
```
|
83
83
|
|
84
|
-
### Callback
|
84
|
+
### Callback usage
|
85
85
|
|
86
86
|
```Ruby
|
87
87
|
class Callback_object
|
@@ -132,4 +132,4 @@ end
|
|
132
132
|
|
133
133
|
```Ruby
|
134
134
|
socket.write parser.raw_data
|
135
|
-
```
|
135
|
+
```
|
data/lib/segregate/version.rb
CHANGED
data/lib/segregate.rb
CHANGED
@@ -85,8 +85,6 @@ class Segregate
|
|
85
85
|
@header_orders.push 'content-length' unless @header_orders.include? 'content-length'
|
86
86
|
@headers.delete 'content-encoding'
|
87
87
|
@header_orders.delete 'content-encoding'
|
88
|
-
else
|
89
|
-
raise "ERROR: parsing message body not complete"
|
90
88
|
end
|
91
89
|
end
|
92
90
|
|
@@ -104,8 +102,6 @@ class Segregate
|
|
104
102
|
end
|
105
103
|
|
106
104
|
def parse data
|
107
|
-
raise "ERROR: parsing completed" if @body_complete
|
108
|
-
|
109
105
|
data = StringIO.new data
|
110
106
|
|
111
107
|
read_first_line data unless @first_line_complete
|
@@ -131,10 +127,6 @@ class Segregate
|
|
131
127
|
parse_request_line line
|
132
128
|
elsif line =~ STATUS_LINE
|
133
129
|
parse_status_line line
|
134
|
-
elsif line =~ UNKNOWN_REQUEST_LINE
|
135
|
-
raise "ERROR: Unknown http method: %s" % line[/^\S+/]
|
136
|
-
else
|
137
|
-
raise "ERROR: Unknown first line: %s" % line
|
138
130
|
end
|
139
131
|
|
140
132
|
@first_line_complete = true
|
data/spec/segregate_spec.rb
CHANGED
@@ -38,14 +38,6 @@ describe Segregate do
|
|
38
38
|
it 'accepts one argument' do
|
39
39
|
expect(@parser).to respond_to(:parse).with(1).argument
|
40
40
|
end
|
41
|
-
|
42
|
-
it 'errors if an incorrect first line is received' do
|
43
|
-
expect{ @parser.parse "fail\r\n" }.to raise_error RuntimeError, 'ERROR: Unknown first line: fail'
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'errors if an incorrect http method is received' do
|
47
|
-
expect{ @parser.parse "FAIL /endpoint HTTP/1.1\r\n" }.to raise_error RuntimeError, 'ERROR: Unknown http method: FAIL'
|
48
|
-
end
|
49
41
|
end
|
50
42
|
|
51
43
|
context 'a request line has been parsed' do
|
@@ -79,6 +71,18 @@ describe Segregate do
|
|
79
71
|
expect(@parser.request_line).to match Segregate::REQUEST_LINE
|
80
72
|
expect(@parser.request_line).to eq "GET /endpoint HTTP/2.3"
|
81
73
|
end
|
74
|
+
|
75
|
+
it 'returns a modified major http version request line' do
|
76
|
+
@parser.major_http_version = 2
|
77
|
+
expect(@parser.request_line).to match Segregate::REQUEST_LINE
|
78
|
+
expect(@parser.request_line).to eq "GET /endpoint HTTP/2.1"
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'returns a modified minor http version request line' do
|
82
|
+
@parser.minor_http_version = 2
|
83
|
+
expect(@parser.request_line).to match Segregate::REQUEST_LINE
|
84
|
+
expect(@parser.request_line).to eq "GET /endpoint HTTP/1.2"
|
85
|
+
end
|
82
86
|
end
|
83
87
|
|
84
88
|
describe '#status_line' do
|
@@ -171,10 +175,6 @@ describe Segregate do
|
|
171
175
|
it 'returns the uri methods' do
|
172
176
|
expect(@parser.path).to eq '/endpoint'
|
173
177
|
end
|
174
|
-
|
175
|
-
it 'raises an error if uri does not respond to the method' do
|
176
|
-
expect{ @parser.not_present }.to raise_error NoMethodError, /undefined method `not_present'/
|
177
|
-
end
|
178
178
|
end
|
179
179
|
|
180
180
|
describe '#respond_to?' do
|
@@ -429,18 +429,6 @@ describe Segregate do
|
|
429
429
|
end
|
430
430
|
end
|
431
431
|
|
432
|
-
describe '#update_content_length' do
|
433
|
-
it 'raises an error if the body is not complete' do
|
434
|
-
expect{ @parser.update_content_length }.to raise_error RuntimeError, 'ERROR: parsing message body not complete'
|
435
|
-
end
|
436
|
-
end
|
437
|
-
|
438
|
-
describe '#raw_data' do
|
439
|
-
it 'raises an error if the body is not complete' do
|
440
|
-
expect{ @parser.raw_data }.to raise_error RuntimeError, 'ERROR: parsing message body not complete'
|
441
|
-
end
|
442
|
-
end
|
443
|
-
|
444
432
|
context 'the body parsing is completed' do
|
445
433
|
before(:each) do
|
446
434
|
@parser.parse "27\r\nThis is the second content!\r\n"
|