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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ffac6eac2b627e157f087d6c92d6e7e52f0e76af114a8a575e2e0fef512d388
4
- data.tar.gz: 48c09ef3b224fc67f74a3eead572bf729b9110643b0f837c1034147c57eddada
3
+ metadata.gz: a07247036ade5e265e7cdeecad88340fcc0facfb27d84c4c9e16cf37453e62e6
4
+ data.tar.gz: 4698c72c5b546788f037c88d3ca93993bc17199a6eea89b0d1ac402220ea1767
5
5
  SHA512:
6
- metadata.gz: faccb4442498bf24e101933af5b7f46c9c4f6ecf5c6f2a3fe912254b3171b3c0e8ebec73b41dc10916250aeca8e36ef5cc78e58b33e3860d8812e5b4616cc3de
7
- data.tar.gz: 68b22b8a8a053546a1131ac67cb7201b60856d7f2012519d19e8ee40766788954079782cc4dea96233c3ba7df6fd23111f5c90b41b800f3319bac70644264151
6
+ metadata.gz: 2ddbba65cd94493229a768566b1f64815c4a0020340a1158a15a9ed1373f565fc73fb542887fe7eda402371f50ddc6ec57e89f5a2dece8cd60cd2cb29fdba90a
7
+ data.tar.gz: c7d1007d47da1dea0572ef33a3d70b373c3d6189a48afd798212669c6f2d25989c6808328eaab0b01fca45210ff0c233b11688411f9be40cc401a1b3a89c5429
@@ -14,7 +14,7 @@ class Midori::Connection
14
14
  @socket = socket
15
15
  @monitor = nil
16
16
  @close_flag = false
17
- @data = ''
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 !@data == ''
31
- # :nocov:
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
- @monitor.writable? ? @socket.write_nonblock(data) : @data << data
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # Midori Module
2
2
  module Midori
3
3
  # Current Version Code
4
- VERSION = '0.5.1'.freeze
4
+ VERSION = '0.5.2'.freeze
5
5
  end
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.1
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-23 00:00:00.000000000 Z
11
+ date: 2018-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: murasaki