midori.rb 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/midori/connection.rb +21 -9
- data/lib/midori/response.rb +1 -0
- data/lib/midori/server.rb +3 -0
- data/lib/midori/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a07247036ade5e265e7cdeecad88340fcc0facfb27d84c4c9e16cf37453e62e6
|
4
|
+
data.tar.gz: 4698c72c5b546788f037c88d3ca93993bc17199a6eea89b0d1ac402220ea1767
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ddbba65cd94493229a768566b1f64815c4a0020340a1158a15a9ed1373f565fc73fb542887fe7eda402371f50ddc6ec57e89f5a2dece8cd60cd2cb29fdba90a
|
7
|
+
data.tar.gz: c7d1007d47da1dea0572ef33a3d70b373c3d6189a48afd798212669c6f2d25989c6808328eaab0b01fca45210ff0c233b11688411f9be40cc401a1b3a89c5429
|
data/lib/midori/connection.rb
CHANGED
@@ -14,7 +14,7 @@ class Midori::Connection
|
|
14
14
|
@socket = socket
|
15
15
|
@monitor = nil
|
16
16
|
@close_flag = false
|
17
|
-
@
|
17
|
+
@buffer = ''
|
18
18
|
listen(socket)
|
19
19
|
end
|
20
20
|
|
@@ -27,12 +27,8 @@ class Midori::Connection
|
|
27
27
|
receive_data(monitor)
|
28
28
|
end
|
29
29
|
if monitor.writable?
|
30
|
-
if !@
|
31
|
-
|
32
|
-
# Leave for corner cases
|
33
|
-
monitor.io.write_nonblock(@data)
|
34
|
-
@data = ''
|
35
|
-
# :nocov:
|
30
|
+
if !@buffer.empty?
|
31
|
+
send_buffer
|
36
32
|
elsif @close_flag
|
37
33
|
close_connection
|
38
34
|
end
|
@@ -41,9 +37,25 @@ class Midori::Connection
|
|
41
37
|
end
|
42
38
|
|
43
39
|
# Send message to client
|
44
|
-
# @param [String] data data to send
|
40
|
+
# @param [Midori::Response | String] data data to send
|
45
41
|
def send_data(data)
|
46
|
-
@
|
42
|
+
@buffer << (data.is_a?(String) ? data : data.to_s)
|
43
|
+
send_buffer
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
|
47
|
+
# Send buffer immediately
|
48
|
+
private def send_buffer
|
49
|
+
if @monitor.writable?
|
50
|
+
written = @socket.write_nonblock(@buffer)
|
51
|
+
@buffer = @buffer.byteslice(written..-1)
|
52
|
+
end
|
53
|
+
nil
|
54
|
+
rescue IO::EAGAINWaitWritable => _e
|
55
|
+
# :nocov:
|
56
|
+
# Unknown Reason Resource Conflict
|
57
|
+
nil
|
58
|
+
# :nocov:
|
47
59
|
end
|
48
60
|
|
49
61
|
# Close the connection
|
data/lib/midori/response.rb
CHANGED
@@ -21,6 +21,7 @@ class Midori::Response
|
|
21
21
|
# Generate header string from hash
|
22
22
|
# @return [String] generated string
|
23
23
|
def generate_header
|
24
|
+
@header['Content-Length'] = @body.bytesize if @header['Content-Length'].nil? && !@body.empty?
|
24
25
|
@header.map do |key, value|
|
25
26
|
"#{key}: #{value}\r\n"
|
26
27
|
end.join
|
data/lib/midori/server.rb
CHANGED
@@ -43,8 +43,11 @@ module Midori::Server
|
|
43
43
|
close_connection
|
44
44
|
# Ignore client's disconnection
|
45
45
|
rescue => e
|
46
|
+
# :nocov:
|
47
|
+
# Leave for corner cases
|
46
48
|
close_connection
|
47
49
|
@logger.warn "#{@request.ip} - - #{e.class} #{e.backtrace.join("\n")}".yellow
|
50
|
+
# :nocov:
|
48
51
|
end
|
49
52
|
end)
|
50
53
|
end.call
|
data/lib/midori/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: midori.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HeckPsi Lab
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: murasaki
|