degzipper 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/Rakefile +5 -0
- data/degzipper.gemspec +1 -0
- data/lib/degzipper/middleware.rb +1 -1
- data/lib/degzipper/version.rb +1 -1
- data/spec/degzipper_spec.rb +80 -0
- metadata +20 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1151434f8833470a8de8ba07d73bd3430c2330e9
|
4
|
+
data.tar.gz: 51b24f05136a687187e2977a6bf7e589d118c836
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7f93d6007d513925ab291f3757e502d7757d15126585116725d5ffa8e7b75c14f981d0802a2d1bdeb35d338525b425cbaf5b844b0c5d47f991822b4d631a21e
|
7
|
+
data.tar.gz: 19149bcb8ac05e5470c0f35b13a626ad474dfeb18cdd754dc9e31bd599ee1866592e7f9bf3299e452a52ced7b5980525f700a85285c13472b675e78578e45fc6
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Rakefile
CHANGED
data/degzipper.gemspec
CHANGED
data/lib/degzipper/middleware.rb
CHANGED
@@ -17,7 +17,7 @@ module Degzipper
|
|
17
17
|
extracted = decode(env['rack.input'], env['HTTP_CONTENT_ENCODING'])
|
18
18
|
|
19
19
|
env.delete('HTTP_CONTENT_ENCODING')
|
20
|
-
env['CONTENT_LENGTH'] = extracted.
|
20
|
+
env['CONTENT_LENGTH'] = extracted.bytesize
|
21
21
|
env['rack.input'] = StringIO.new(extracted)
|
22
22
|
end
|
23
23
|
|
data/lib/degzipper/version.rb
CHANGED
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'degzipper'
|
2
|
+
require 'json'
|
3
|
+
require 'rack'
|
4
|
+
require 'zlib'
|
5
|
+
|
6
|
+
RSpec.describe Degzipper::Middleware do
|
7
|
+
def gzip(content)
|
8
|
+
string_io = StringIO.new
|
9
|
+
|
10
|
+
gz = Zlib::GzipWriter.new(string_io)
|
11
|
+
gz.write content
|
12
|
+
gz.close
|
13
|
+
|
14
|
+
string_io.string
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:middleware) do
|
18
|
+
Degzipper::Middleware.new(-> (env) do
|
19
|
+
req = Rack::Request.new(env)
|
20
|
+
|
21
|
+
body = JSON.dump(
|
22
|
+
body: req.body.read,
|
23
|
+
content_encoding: env['HTTP_CONTENT_ENCODING'],
|
24
|
+
length: req.content_length.to_i
|
25
|
+
)
|
26
|
+
|
27
|
+
[200, {}, [body]]
|
28
|
+
end)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'passes through a non-gzipped request body' do
|
32
|
+
_, _, body = middleware.call(Rack::MockRequest.env_for(
|
33
|
+
'/',
|
34
|
+
method: 'POST',
|
35
|
+
input: 'hello'
|
36
|
+
))
|
37
|
+
|
38
|
+
parsed_body = JSON.parse(body.first)
|
39
|
+
|
40
|
+
expect(parsed_body).to eq(
|
41
|
+
'body' => 'hello',
|
42
|
+
'content_encoding' => nil,
|
43
|
+
'length' => 5
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'extracts a gzipped request body' do
|
48
|
+
_, _, body = middleware.call(Rack::MockRequest.env_for(
|
49
|
+
'/',
|
50
|
+
method: 'POST',
|
51
|
+
input: gzip('hello'),
|
52
|
+
'HTTP_CONTENT_ENCODING' => 'gzip'
|
53
|
+
))
|
54
|
+
|
55
|
+
parsed_body = JSON.parse(body.first)
|
56
|
+
|
57
|
+
expect(parsed_body).to eq(
|
58
|
+
'body' => 'hello',
|
59
|
+
'content_encoding' => nil,
|
60
|
+
'length' => 5
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'sets the correct content length for UTF-8 content' do
|
65
|
+
_, _, body = middleware.call(Rack::MockRequest.env_for(
|
66
|
+
'/',
|
67
|
+
method: 'POST',
|
68
|
+
input: gzip('你好'),
|
69
|
+
'HTTP_CONTENT_ENCODING' => 'gzip'
|
70
|
+
))
|
71
|
+
|
72
|
+
parsed_body = JSON.parse(body.first)
|
73
|
+
|
74
|
+
expect(parsed_body).to eq(
|
75
|
+
'body' => '你好',
|
76
|
+
'content_encoding' => nil,
|
77
|
+
'length' => 6
|
78
|
+
)
|
79
|
+
end
|
80
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: degzipper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Hammond
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-05-
|
12
|
+
date: 2015-05-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -39,6 +39,20 @@ dependencies:
|
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
42
56
|
description: Rack middleware to inflate incoming Gzip data from HTTP requests.
|
43
57
|
email:
|
44
58
|
- andrew@evertrue.com
|
@@ -47,6 +61,7 @@ extensions: []
|
|
47
61
|
extra_rdoc_files: []
|
48
62
|
files:
|
49
63
|
- ".gitignore"
|
64
|
+
- ".rspec"
|
50
65
|
- Gemfile
|
51
66
|
- LICENSE.txt
|
52
67
|
- README.md
|
@@ -56,6 +71,7 @@ files:
|
|
56
71
|
- lib/degzipper/middleware.rb
|
57
72
|
- lib/degzipper/rails.rb
|
58
73
|
- lib/degzipper/version.rb
|
74
|
+
- spec/degzipper_spec.rb
|
59
75
|
homepage: http://github.com/andrhamm/degzipper
|
60
76
|
licenses:
|
61
77
|
- MIT
|
@@ -80,4 +96,5 @@ rubygems_version: 2.2.2
|
|
80
96
|
signing_key:
|
81
97
|
specification_version: 4
|
82
98
|
summary: Rack middleware to inflate incoming Gzip data from HTTP requests.
|
83
|
-
test_files:
|
99
|
+
test_files:
|
100
|
+
- spec/degzipper_spec.rb
|