falcon 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5998b68f454477fcb11ec2571d14eac6f231345175f8bebac905b951ba391dbd
4
- data.tar.gz: b2c5eb9aa083eee62480aea639855a7eb5244f1485aab7b8cb65e936e69b132c
3
+ metadata.gz: f3429e33911513a17a66a9dad747942f377f57dd4f2351ec59cb3e17047407ca
4
+ data.tar.gz: 7b6339640be53ec16971524684e12e1e1a77a9bd2f1ebacfbc1abeb5eb3754be
5
5
  SHA512:
6
- metadata.gz: cf9842920c7c80129a1f4660ae4a769530660c88696bc22464f8211b6d3cb0c358b9ea63f655f22d7c9676970400214ca8eb56efc65c97eeb967bb091264178e
7
- data.tar.gz: 8645f34edab0d4365eb8092421a2a72b77416ca71546fdad28c7c278c3e7de99f0f1d0ff6c20dc84d1fcf7d9831a120db8e7b114a68cc4d7dad703a0b754a1b0
6
+ metadata.gz: 1c1780fd09c7840daafb3b4f4472c622a87f077182bc334ca09406a38bd3d7616bcd1bc78be85debb5fdc48d368460d8d79fd893b99e3e45659f5cce975277f2
7
+ data.tar.gz: 80fa7d8d306a2c4cb4e967051e1e8353d5ac4e41ab41a1cf3ba43fb842713f74a32e8d64e2b201d30350c7f5b5bd30c77a5c60fad4c04e83321b12687806807b
data/falcon.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.require_paths = ["lib"]
18
18
 
19
19
  spec.add_dependency("async-io", "~> 1.6")
20
- spec.add_dependency("async-http", "~> 0.10")
20
+ spec.add_dependency("async-http", "~> 0.11")
21
21
  spec.add_dependency("async-container", "~> 0.3")
22
22
 
23
23
  spec.add_dependency("rack", ">= 1.0")
@@ -0,0 +1,84 @@
1
+ # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'async/http/server'
22
+
23
+ module Falcon
24
+ class Input
25
+ def initialize(body)
26
+ @body = body
27
+ @chunks = []
28
+
29
+ @buffer = nil
30
+ @closed = false
31
+ end
32
+
33
+ def each(&block)
34
+ while @index < @chunks.count
35
+ chunk = @chunks[@index]
36
+ @index += 1
37
+ yield chunk
38
+ end
39
+
40
+ @body.each do |chunk|
41
+ @chunks << chunk
42
+ yield chunk
43
+ end
44
+
45
+ @closed = true
46
+ end
47
+
48
+ def rewind
49
+ @index = 0
50
+ @closed = false
51
+ end
52
+
53
+ def read(length = nil, buffer = nil)
54
+ unless @buffer
55
+ self.each do |chunk|
56
+ @buffer = chunk
57
+ break
58
+ end
59
+ end
60
+
61
+ if @buffer
62
+ if length and @buffer.bytesize < length
63
+ return @buffer.slice!(0, length)
64
+ else
65
+ buffer = @buffer
66
+ @buffer = nil
67
+ return buffer
68
+ end
69
+ end
70
+ end
71
+
72
+ def eof?
73
+ @closed and @buffer.nil?
74
+ end
75
+
76
+ def gets
77
+ read
78
+ end
79
+
80
+ def close
81
+ @body.close
82
+ end
83
+ end
84
+ end
data/lib/falcon/server.rb CHANGED
@@ -18,6 +18,8 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
+ require_relative 'input'
22
+
21
23
  require 'async/http/server'
22
24
 
23
25
  module Falcon
@@ -36,15 +38,10 @@ module Falcon
36
38
  request_path, query_string = request.path.split('?', 2)
37
39
  server_name, server_port = (request.authority || '').split(':', 2)
38
40
 
39
- input = StringIO.new(request.body || '')
40
- input.set_encoding(Encoding::BINARY)
41
-
42
- headers = request.headers.to_http_hash
43
-
44
41
  env = {
45
42
  'rack.version' => [2, 0, 0],
46
43
 
47
- 'rack.input' => input,
44
+ 'rack.input' => Input.new(request.body),
48
45
  'rack.errors' => $stderr,
49
46
 
50
47
  'rack.multithread' => true,
@@ -70,7 +67,15 @@ module Falcon
70
67
  # I'm not sure what sane defaults should be here:
71
68
  'SERVER_NAME' => server_name || '',
72
69
  'SERVER_PORT' => server_port || '',
73
- }.merge(headers)
70
+ }
71
+
72
+ if content_type = request.headers['content-type']
73
+ env['CONTENT_TYPE'] = content_type
74
+ end
75
+
76
+ request.headers.each do |key, value|
77
+ env["HTTP_#{key.upcase.tr('-', '_')}"] = value
78
+ end
74
79
 
75
80
  env['rack.hijack?'] = true
76
81
  env['rack.hijack'] = lambda do
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Falcon
22
- VERSION = "0.9.0"
22
+ VERSION = "0.10.0"
23
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: falcon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-28 00:00:00.000000000 Z
11
+ date: 2018-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async-io
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.10'
33
+ version: '0.11'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.10'
40
+ version: '0.11'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: async-container
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -159,6 +159,7 @@ files:
159
159
  - lib/falcon.rb
160
160
  - lib/falcon/command.rb
161
161
  - lib/falcon/command/serve.rb
162
+ - lib/falcon/input.rb
162
163
  - lib/falcon/server.rb
163
164
  - lib/falcon/verbose.rb
164
165
  - lib/falcon/version.rb